react-nativebabel-core

Cannot Find Module '@babel/core' react-native


Bundling index.js [development, non-minified] 0.0% (0/1), failed. error: bundling failed: Error: Cannot find module '@babel/core' (While processing preset:

Others have had similar problems which were solved by one of the following:

  1. Uninstalling babel-preset-react-native and installing it again @2.1.0.
    1. Some people could only fix this using yarn and not npm
  2. Moving Babel to devDependancies
  3. Updating the .babelrc file with

{
  "presets": [
    "react-native"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

Unfortunately, not a single one of these worked for me. This happened right after I installed "react-native-svg": "^6.4.1" and "react-native-svg-charts": "^5.2.0".

My package.json is

  "dependencies": {
    "react": "16.0.0",
    "react-native": "0.51.0",
    "react-native-svg": "^6.4.1",
    "react-native-svg-charts": "^5.2.0",
    "react-navigation": "^1.5.11",
    "react-navigation-redux-helpers": "^1.0.5",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-persist": "^5.4.0"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.52",
    "babel-jest": "23.2.0",
    "babel-loader": "^7.1.5",
    "gulp-babel": "^7.0.1",
    "babel-preset-react-native": "2.1.0",
    "jest": "23.3.0",
    "react-test-renderer": "16.4.1"
  },
  "jest": {
    "preset": "react-native"
  }

I've tried a few other things as well, i've removed the node_modules directory about 150 times and reinstalled. always the same error. I've installed @babel/core and babel-core. I've changed the version numbers, i've moved them around from dependencies to devDependencies and back again. nothing is working.

When I do npm install - everything seems to install just fine

When I do react-native run-android it runs through the code, loads it onto the emulated device

Installing APK 'app-debug.apk' on 'Nexus_6_API_28(AVD) - 9' for app:debug Installed on 1 device. BUILD SUCCESSFUL Total time: 10.373 secs

However, immediately after that, when it runs on the device I receive the red screen of death.

Bundling index.js [development, non-minified] 0.0% (0/1), failed. error: bundling failed: Error: Cannot find module '@babel/core' (While processing preset: "/Code/nr/node_modules/babel-preset-react-native/index.js")


Solution

  • Well, after a few hours it seems that at least one of the above DID work. the remaining issue was closing the Metro Bundler terminal and starting a new one. Thanks to a comment on the accepted answer from TransformError with babel-preset-react-native/index.js