react native - crash when initial project "undefined is not a function (evaluating 'reactDevTools.connectToDevTools')"

Viewed 423

I just created a React Native project and it crashes immediately when I type react-native run-android

The error code:

"undefined is not a function (evaluating 'reactDevTools.connectToDevTools')"

Here is my package.json

{
  "name": "MoveObject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "0.57.8"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

If you know how to solve this issue, please let me know.

I tried to solve it by these ways but fail:
1/ npm install
2/ npm install after remove node_modules
3/ I also tried other versions of React Native: 0.57.7 and 0.57.4 but still have the same error.

3 Answers

With npm, you can run npm install --save-dev react-devtools, add "react-devtools": "react-devtools" to the scripts section in your package.json, and then run npm run react-devtools from your project directory using terminal folder to open the DevTools.

try this

It has already been resloved:

You need to add older version of devTools to the "resolutions" of your package.json, so it looks something like this:

{
  "name": "YOUR_APP_NAME",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "0.57.8"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "resolutions": {
    "react-devtools-core": "3.4.3"
  }
}

After that, run yarn or npm install and it will fix the problem.

run the below command, it will fix your issue(for Android only) ----

npm install --save-dev react-devtools-core@3.4.3

Related