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

时间:2018-10-18 10:59:18

标签: reactjs react-native npm npm-scripts

我是本机反应的新手。我在运行

时不断收到此错误
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"
  }
}

2 个答案:

答案 0 :(得分:1)

尝试运行:

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

如果仍然无法正常工作,您可以在此处尝试2种解决方案:

将本机升级到0.57.2

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

以下是适用于RN 0.57的配置:

React native upgrade from babel 6 to babel 7

答案 1 :(得分:1)

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

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