简体   繁体   中英

error: bundling failed: Error: Couldn't find preset “module:metro-react-native-babel-preset” relative to directory “C:\\Users\\…”

Im new to react-native. I keep getting this error when I run

react-native run-android

This is my last package.json, that was working Ok the last time I pushed changes but now it seems to have broken.

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

Try to run:

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

If it still doesn't work you could try 2 solutions here:

Upgrade react-native to 0.57.2

or downgrade babel, from what I know RN 0.54 uses babel 6 not 7.

Here is a configuration that worked for me for RN 0.57:

React native upgrade from babel 6 to babel 7

Please try adding these transform rules into your package.json:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM