找不到模块 '@babel/core' react-native

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:

其他人遇到过类似的问题,已通过以下方式之一解决:

  1. 正在卸载 babel-preset-react-native 并重新安装 @2.1.0。
    1. 有些人只能使用 yarn 而不是 npm 来解决这个问题
  2. 将 Babel 移动到 devDependancies
  3. 更新 .babelrc 文件

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

不幸的是,其中没有一个对我有用。这发生在我安装 "react-native-svg": "^6.4.1" 和 "react-native-svg-charts": "^5.2.0".

之后

我的package.json是

  "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"
  }

我也尝试了一些其他的东西,我已经删除了 node_modules 目录大约 150 次并重新安装。总是同样的错误。我已经安装了@babel/core 和 babel-core。我已经更改了版本号,我已经将它们从 dependencies 移动到 devDependencies 并再次返回。没有任何效果。

当我执行 npm install 时 - 一切似乎都安装得很好

当我做 react-native 运行-android 它 运行 通过代码,将它加载到模拟设备上

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

但是,紧接着,当它 运行 在设备上出现时,我收到了死机的红屏。

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")

好吧,几个小时后,上面的 DID 操作似乎至少有一个成功了。剩下的问题是关闭 Metro Bundler 终端并启动一个新终端。感谢

对已接受答案的评论