index.js:找不到模块'.../@react-native-community/cli/node_modules/metro-react-native-babel-transformat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了index.js:找不到模块'.../@react-native-community/cli/node_modules/metro-react-native-babel-transformat相关的知识,希望对你有一定的参考价值。

我正在尝试在我的项目中添加react-native-navigation @ v2,但它给了我这个错误。谁能告诉我为什么会发生这种情况?

这是我的Package.json

  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "metro-react-native-babel-transformer": "^0.53.1",
    "react": "16.8.3",
    "react-native": "0.59.4",
    "react-native-navigation": "^2.17.0"
  },
  "devDependencies": {
    "@babel/core": "7.4.3",
    "@babel/runtime": "7.4.3",
    "babel-jest": "24.7.1",
    "jest": "24.7.1",
    "metro-react-native-babel-preset": "0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  }
}
答案

确保在项目的根目录中有babel.config.js文件而不是babel.rcand文件babel.config.js应该具有以下内容。

module.exports = {
   presets: ["module:metro-react-native-babel-preset"]
}

希望这可以帮助。快乐的编码!

以上是关于index.js:找不到模块'.../@react-native-community/cli/node_modules/metro-react-native-babel-transformat的主要内容,如果未能解决你的问题,请参考以下文章

错误:找不到模块“C:\Users\Elie\Projects\MEAN\task-manager\api\index.js”

在 npm 中找不到 Babel-loaders 模块,以 react js 开始

模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'babel-preset-react'

错误:找不到模块‘/opt/Ferdi/resources/app.asar/node_modules/@meetfranz/theme/lib/index.js’

找不到模块:无法解析'C: Users test counter-app src'中的'bootstrap / dist / css / bootstrap.cs(代码片

react-native 捆绑失败:错误:找不到模块 /metro-react-native-babel-transformer/src/index.js