错误:捆绑失败:错误:找不到相对于目录“C:\\Users\\...”的预设“module:metro-react-native-babel-preset”

Posted

技术标签:

【中文标题】错误:捆绑失败:错误:找不到相对于目录“C:\\\\Users\\\\...”的预设“module:metro-react-native-babel-preset”【英文标题】:error: bundling failed: Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "C:\\Users\\..."错误:捆绑失败:错误:找不到相对于目录“C:\\Users\\...”的预设“module:metro-react-native-babel-preset” 【发布时间】:2019-03-23 04:07:15 【问题描述】:

我是 react-native 的新手。我运行时不断收到此错误

react-native run-android

这是我的最后一个 package.json,上次我推送更改时它工作正常,但现在它似乎已经坏了。

我的 package.json


  "name": "taxiapp",
  "version": "0.0.1",
  "private": true,
  "scripts": 
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  ,
  "dependencies": 
    "@babel/runtime": "^7.0.0",
    "native-base": "^2.8.0",
    "react": "16.5.0",
    "react-addons-update": "^15.6.2",
    "react-native": "^0.54.1",
    "react-native-maps": "^0.21.0",
    "react-native-router-flux": "^4.0.5",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  ,
  "devDependencies": 
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "^0.48.1",
    "react-test-renderer": "16.5.0",
    "redux-logger": "^3.0.6"
  ,
  "jest": 
    "preset": "react-native"
  

【问题讨论】:

【参考方案1】:

尝试运行:

del %appdata%\Temp\react-* & del %appdata%\Temp\metro-* & del %appdata%\Temp\haste-* & watchman watch-del-all & npm start -- --reset-cache

如果仍然不起作用,您可以在这里尝试 2 个解决方案:

将 react-native 升级到 0.57.2

或降级 babel,据我所知,RN 0.54 使用 babel 6 而不是 7。

这是一个适用于 RN 0.57 的配置:

React native upgrade from babel 6 to babel 7

【讨论】:

谢谢!现在我得到这个新错误:错误:捆绑失败:错误:无法从C:\Users\Santiago\Google Drive\files\php\repos\taxiapp\node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js解析模块scheduler/tracing:模块scheduler/tracing在Haste模块映射中不存在【参考方案2】:

请尝试将这些转换规则添加到您的 package.json 中:

"jest": 
  "preset": "react-native",
  "transform": 
    "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
  ,
  "transformIgnorePatterns": [
    "node_modules/(?!(jest-)?react-native)"
  ]
,

【讨论】:

以上是关于错误:捆绑失败:错误:找不到相对于目录“C:\\Users\\...”的预设“module:metro-react-native-babel-preset”的主要内容,如果未能解决你的问题,请参考以下文章

Webpack + Babel:找不到相对于目录的预设“es2015”

找不到相对于目录的预设“模块:metro-react-native-babel-preset”

詹金斯“找不到捆绑命令”

我的 AppCenter 失败并出现错误“在项目目录中找不到 `Podfile'”并且我的项目不使用 cocoapods

还原数据库总提示目录查找失败系统错误3,找不到路径

捆绑失败:错误:ENOENT:没有这样的文件或目录,scandir React Native