React-native: undefined is not an object (evaluating 'ReactInternals.ReactCurrentOwner')

Created on 9 May 2017  ·  24Comments  ·  Source: facebook/react-native

Description

The last couple of days I've been attempting to debug the current React Native master (updated the HEAD a few times) on either iOS or Android, however app execution fails immediately after receiving the bundle with the exception:

undefined is not an object (evaluating 'ReactInternals.ReactCurrentOwner')

I've attempted clean app rebuilds many times:

watchman watch-del-all
rm -rf ./node_modules
yarn cache clean
rm -rf $TMPDIR/react-*
yarn install
npm start -- --reset-cache

Also, cleaned the Android builds (./gradlew clean) and iOS builds ("Clean" and "Clean Build Folder") and rebuilt.

Reproduction Steps and Sample Code

  1. Check out RN master.

  2. Build the Android libs using:

./gradlew installArchives
  1. Check in the resultant android/ directory (force add as it's .gitignore'd) and push to a Github branch.

  2. In a RN app swap from the NPM published package to the published branch e.g.

yarn remove react-native
yarn add github:benjamin-dobell/react-native#builds/dynamic-toolbar
  1. Rebuild the app cd android; ./gradlew clean; ./gradlew installDebug, or for iOS from XCode.

  2. Launch the RN packager:

yarn start

__Note:__ If you haven't grabbed flowtype from master this will fail here. I just temporarily replaced the spread operator usage in type definitions with copy and paste contents.

  1. Launch the app on an Android or iOS device. Wait for the packager to bundle the package.

Error then occurs.

It's perhaps worth noting that, _I believe_, this is the exact procedure I've followed in the past to build and test (and eventually contribute back) my RN forks.

Solution

Unsure.

Additional Information

  • React Native version: 73fc439bc03b457d7bcebdb3fd230e470af52e38
  • Platform: Android & iOS
  • Development Operating System: macOS 10.12.4 (16E195)
  • Dev tools:

    • android-ndk-r10e

    • Xcode 8.3.2 (Build version 8E2002)

    • node v7.9.0

    • yarn 0.23.4

    • npm 4.2.0

Locked

Most helpful comment

@winterrain5 As I mentioned, make sure you've installed the correct version of React. If you're using React Native 0.45:

yarn add [email protected]

All 24 comments

It doesn't seem obviously related to me, but perhaps a hint toward the underlying cause. When you run the packager with:

yarn start -- --reset-cache

instead of simply yarn start.

You end up with a few warnings about duplicate modules:

React packager ready.

Loading dependency graph...jest-haste-map: @providesModule naming collision:
  Duplicate module name: babylon
  Paths: <PROJECT PATH>/node_modules/react-native/node_modules/babylon/package.json collides with <PROJECT PATH>/node_modules/react-native/node_modules/babel-traverse/node_modules/babylon/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
  Duplicate module name: core-js
  Paths: <PROJECT PATH>/node_modules/react-native/node_modules/core-js/package.json collides with <PROJECT PATH>/node_modules/react-native/node_modules/fbjs/node_modules/core-js/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.
Loading dependency graph, done.

Full trace (from iOS):

undefined is not an object (evaluating 'ReactInternals.ReactCurrentOwner')

<unknown>
   ReactGlobalSharedState.js:18:36
loadModuleImplementation
   require.js:174:12
<unknown>
   ReactDebugTool.js:18:39
loadModuleImplementation
   require.js:174:12
<unknown>
   ReactInstrumentation.js:19:31
loadModuleImplementation
   require.js:174:12
<unknown>
   ReactNativeMount.js:15:35
loadModuleImplementation
   require.js:174:12
<unknown>
   ReactNativeStack.js:16:31
loadModuleImplementation
   require.js:174:12
<unknown>
   ReactNative.js:18:12
loadModuleImplementation
   require.js:174:12
<unknown>
   NativeMethodsMixin.js:14:26
loadModuleImplementation
   require.js:174:12
<unknown>
   View.js:14:35
loadModuleImplementation
   require.js:174:12
<unknown>
   MapMarker.js:25:5
loadModuleImplementation
   require.js:174:12
<unknown>
   MapView.js:12
loadModuleImplementation
   require.js:174:12
<unknown>
   index.js:1
loadModuleImplementation
   require.js:174:12
<unknown>
   <APP FILE>:13
loadModuleImplementation
   require.js:174:12
<unknown>
   <APP FILE>:19
loadModuleImplementation
   require.js:174:12
<unknown>
   routes.js:1
loadModuleImplementation
   require.js:174:12
<unknown>
   Navigator.js:12
loadModuleImplementation
   require.js:174:12
<unknown>
   <APP FILE>:49
loadModuleImplementation
   require.js:174:12
<unknown>
   setup.js:22
loadModuleImplementation
   require.js:174:12
<unknown>
   index.ios.js:4:22
loadModuleImplementation
   require.js:174:12
guardedLoadModule
   require.js:119:45
global code
   <unknown file>:0

I could have sworn I updated my React peer dependency. Apparently not!

That was the cause. Sorry!

A note to anyone else trying to run RN from master. Double check the react version in RN's package.json matches the one in your app's yarn lockfile.

i have the same problem in the ios,is there anybody solved it?

@winterrain5 As I mentioned, make sure you've installed the correct version of React. If you're using React Native 0.45:

yarn add [email protected]

i got the same problem after upgrading to 0.45

I'm assuming that you also need to update this too if you have it?

"react-test-renderer": "16.0.0-alpha.12"

@Benjamin-Dobell Thank you !

i have the same question in my android project. how to fix it ? i, package.json:
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.45.1"
}

Hi
Same problem like above
My package.json

"name": "RNDemo",
"version": "1.0.0",
"description": "",
"main": "index.android.js",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.6.1",
"react-native": "^0.46.0"
}

How to fixed it ??

@Benjamin-Dobell It worked. Thanks.

Hmm. I'm getting the same message with react-native: 0.46.0 and react: 16.0.0-alpha.12. Probably me doing something stupid on my machine though as I get the same issue no matter what react native example I'm running.

EDIT: My issue was that I did not move the ios project to an ios sub folder.

This is my package.json. Is there any workaround?
{ "name": "NowPurchase", "version": "0.1.0", "private": true, "devDependencies": { "react-native-scripts": "0.0.50", "jest-expo": "~18.0.0", "react-test-renderer": "16.0.0-alpha.12" }, "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", "scripts": { "start": "react-native-scripts start", "eject": "react-native-scripts eject", "android": "react-native-scripts android", "ios": "react-native-scripts ios", "test": "node node_modules/jest/bin/jest.js --watch" }, "jest": { "preset": "jest-expo" }, "dependencies": { "expo": "^18.0.3", "react": "16.0.0-alpha.12", "react-native": "^0.45.1", "react-native-collapsing-toolbar": "^1.0.0-beta.4", "react-native-drawer-menu": "^0.2.4", "react-native-keyboard-aware-scroll-view": "^0.2.9", "react-native-material-design": "^0.3.7", "react-native-util": "^1.0.2", "react-native-vector-icons": "^4.3.0", "react-navigation": "^1.0.0-beta.11", "util": "*" } }

Hello
I had same issue when migrating from recat native 0.42.1 to 0.47.0
I did the following and it fixed almost all my issues :

  • delete/remove yourProject/node-modules folder
  • set up package.json with "react": "16.0.0-alpha.12" and "react-native": "0.47.0"
  • npm install
  • cd android && gradlew clean
  • cd.. && npm start -- --reset-cache
    (some react native libraries I had had to be updated also to last version supporting 0.47)

Thanks! Resolved it!

followed @tiofabby @saayani But, NOT WORKING.

image

package.json configuration is as below.

{
    "name": "AwesomeProject",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "react": "16.0.0-alpha.12",
        "react-native": "0.47.0"
    },
    "devDependencies": {
        "babel-jest": "20.0.0",
        "babel-preset-react-native": "1.9.1",
        "jest": "20.0.0",
        "react-test-renderer": "16.0.0-alpha.6"
    },
    "jest": {
        "preset": "react-native"
    }
}

OK. I got it resolved by doing the things below.

1) Check in NPM repo all dependencies are latest for the Project Development.
2) Update each dependencies and run react native again.

Problem Solved ! @tiofabby @saayani 👍

@tiofabby it works for me ,i used

"dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "^0.47.2"
  }

解决方法:把react,react-native安装如下版本就好了
"react": "^16.0.0-alpha.12",
"react-native": "^0.46.4",

解决方法:把react,react-native安装如下版本就好了
What...?

I removed the '^' in front of "16.0.0-alpha.12" and it worked.

Yep I added [email protected] and it worked for me.
you guys saved my life hahaha thks !!

[email protected] worked for me too. thanks

Was this page helpful?
0 / 5 - 0 ratings