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

Posted

技术标签:

【中文标题】index.js:找不到模块\'.../@react-native-community/cli/node_modules/metro-react-native-babel-transformation/src/index.js\'(空))【英文标题】:index.js: Cannot find module '.../@react-native-community/cli/node_modules/metro-react-native-babel-transformation/src/index.js' (null))index.js:找不到模块'.../@react-native-community/cli/node_modules/metro-react-native-babel-transformation/src/index.js'(空)) 【发布时间】:2019-09-04 09:29:03 【问题描述】:

我正在尝试在我的项目中添加 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"
  

【问题讨论】:

【参考方案1】:

确保您的项目根目录中有babel.config.js 文件而不是babel.rc,并且文件babel.config.js 应具有以下内容。

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

【讨论】:

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

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

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

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

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

未找到模块:错误:无法解析 React-js?

找不到模块:错误:无法解析模块“fs”