React-native: Error: Couldn't find preset "module:metro-react-native-babel-preset"

Created on 30 Oct 2018  路  5Comments  路  Source: facebook/react-native

Environment

Environment:
OS: macOS High Sierra 10.13.6
Node: 10.11.0
Yarn: 1.9.4
npm: 6.4.1
Watchman: 4.9.0
Xcode: Xcode 10.0 Build version 10A255
Android Studio: 3.2 AI-181.5540.7.32.5014246

Packages: (wanted => installed)
react: 16.6.0 => 16.6.0
react-native: 0.51.0 => 0.51.0

Description

When I was trying to recreate news ios and android folders. It throw a error as bellow:

git-upgrade ERR! An error occurred during upgrade:
git-upgrade ERR! Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/my_usr/Downloads/myproject/app"
    at /usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at compile (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-register/lib/node.js:103:45)
    at loader (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-register/lib/node.js:144:14)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/react-native-git-upgrade/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
git-upgrade ERR! Restore initial sources

Reproducible Demo

"dependencies": {
"moment": "^2.22.2",
"prop-types": "15.6.2",
"react": "16.6.0",
"react-native": "0.51.0",
"react-navigation": "2.5.3",
"underscore.string": "3.3.4"
},

BY RUNNING command react-native-git-upgrade 0.51.0

Ran Commands Locked

Most helpful comment

rename .babelrc to something else, then run react-native-git-upgrade. After upgrading rename it back.

All 5 comments

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The ":rewind:Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

rename .babelrc to something else, then run react-native-git-upgrade. After upgrading rename it back.

I am closing this issue because it does not appear to have been verified on the latest release, and there has been no followup in a while.

If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here.

what happens if you already have the latest RN?!

Dependencies
react-native: 0.57.8
jest: 23.6.0

In your package.json file, modify the transform value in the jest object to look like this:

"jest": {
    "preset": "react-native",
    "transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js" },
     ...
  }
Was this page helpful?
0 / 5 - 0 ratings