react-native: Error: Couldn't find preset "module:metro-react-native-babel-preset"
Environment
React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel® Core™ i7-4750HQ CPU @ 2.00GHz Memory: 68.43 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 9.8.0 - /usr/local/bin/node Yarn: 1.9.4 - /usr/local/bin/yarn npm: 6.3.0 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 IDEs: Xcode: 10.1/10O23u - /usr/bin/xcodebuild npmPackages: react: ^16.5.2 => 16.5.2 react-native: ^0.57.0 => 0.57.0 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 1.2.0 react-native-git-upgrade: 0.2.7 react-native-rename: 2.2.2
Description
When trying to run “react-native-git-upgrade” it gives the following error:
git-upgrade ERR! An error occurred during upgrade:
Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "Users/...
Reproducible Demo
Try to upgrade from React Native 0.56 to 0.57 with “react-native-git-upgrade”.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 84
- Comments: 71 (7 by maintainers)
I seemed to have solved this by removing everything in the
babelrc
file:react-native-git-upgrade
then tries to re-add this during installation. I kept removing it and re-saving the file, and it continued without crashing. Then I added the contents back.@Amnesthesia 's workaround allowed my upgrade to progress a bit further, but eventually
react-native-git-upgrade
re-added the preset to .babelrc file and failed at the same error in the end.My solution was to rename
.babelrc
->.babelrc2
during upgrade which worked. I restored the.babelrc
config after the upgrade.Happened to me when upgrading
v0.57.0
->v0.57.1
andv0.57.1
->v0.57.2
.yarn add metro-react-native-babel-preset --dev
https://github.com/facebook/metro/tree/master/packages/metro-react-native-babel-presetYou can try this: Change the line of file “.babelrc”: from { “presets”: [“module:metro-react-native-babel-preset”] } to { “presets”: [“react-native”] }
It worked for me.
@calcazar Try this
babel.config.js
with the following content (basically equivalent to stock.babelrc
).babelrc
yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core
I didn’t have to add any transforms to jest after that.
It should be fixed now, make sure you are using metro
0.45.6
(a simple-reinstall of the node_modules should be enough).Worked beautifully! 👍🏼
@dylancompanjen so what worked for my case was I added this to my jest config in my package.json
Hope it helps
This is still happening with a fresh project using latest react-native version (0.57.4)
How to reproduce
npm test
Why? I never use
react-native-git-upgrade
whenever I update my projects, I prefer to do things manually to have granular control over the changes I apply 🤷♂️Moreover, as discussed here, there is noone currently maintaining that portion of the CLI - so it’s always a risk to use it.
adding the
transform
to my jest config in package.json fixed it for mejust simply delete
.babelrc
in ##your## project root. you will save your day. After Everything clean and update done, re-add.bablerc
with the content you deleted beforetl;dr: Please publish a new release of
react-native-git-upgrade
to npmA fix for this landed in https://github.com/facebook/react-native/pull/20790, but a new release of
react-native-git-upgrade
including this commit has not yet been published. I was able to successfully upgrade by cloning the react-native repo, runningnpm i
in thereact-native-git-upgrade
directory, then from my project from 0.57.0 to 0.57.2 by runningWould also close https://github.com/facebook/react-native/issues/21531 and https://github.com/facebook/react-native/issues/18886 (dupes)
FWIW, https://facebook.github.io/react-native/docs/upgrading.html still recommends
react-native-git-upgrade
, and specifically installing it from npm.@canyara I already added metro-react-native-babel-preset (and updated my babelrc). The bug still appears.
The problem persists, when I use the ‘module:metro-react-native-babel-preset’, the application works but don’t work the tests. And I use the preset ‘react-native’, the application don’t work, but the tests works.
I am also getting exactly the same error when running the tests on a fresh react-native 0.57.1 project. To reproduce:
Steps
Output
Worth mentioning that there is an open related issue on the metro repository: https://github.com/facebook/metro/issues/242
Thought I should share it here since I can’t see any activity around this issue.
Same here, trying to upgrade from 0.53 to 0.57 with “react-native-git-upgrade” on Ubuntu 18.04 LTS
@rszalski’s solution worked for me;
@mezod I managed to work around it by deleting the
.babelrc
file and adding ababel.config.js
Discussed in more detail here: https://github.com/facebook/metro/issues/242#issuecomment-431350665
To upgrade iOS and Android files like any other RN upgrade ?
react-native-git-upgrade
directly from the0.56.0
didn’t work either.I met the same situation. I initialized a project with
react-native-cli
, then I integratedMboX
and use decorators, so mypackage.json
and.babelrc
like this:When i run
react-native-git-upgrade
, i get this error:Then i try to remove the
@babel/plugin-proposal-decorators
plugin from.babelrc
like this:I get another error:
Then i change
.babelrc
tobabel.config.js
:Run
react-native-git-upgrade
, it work!I found that if I remove the
.babelrc
first and runreact-native-git-upgrade
, it also work!(need to put.babelrc
back after upgraded.)Hope this helps someone else.
I always get error while installing vector icons
error: bundling failed: Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/home/....
I tried all ways to resolve this issue but none of them is working… I am tired solving this since 2 days
Do we have a status on this? I started a new project, brought my JS source in to it, ran jest and I get Couldn’t find preset “module:metro-react-native-babel-preset”
What solved my problem in the end, was simply building the project under Xcode and then running it with
react-native run-ios
.If you’re attempting to upgrade your project and you’re stuck and unable to solve any problem, then this is what I did. Not the best way, but it works.
react-native run-ios
, if it fails ensure to build it in xcode, abd then re-test it withreact-native run-ios
commandIf you’re also building for Android, you’ll need to reconfigure your Android project (manifest, build.gradle, etc)
If you run into some problems then you might have skipped a step or I might have forgotten to mention something.
I ran into a few issues, but that’s because I forgot to add a few Babel plugins i was using for mobx.
This worked for me. Took a while, but in the end saved time instead of trying to understand vague error messages.
Same issue here when trying to upgrade over the last month.
0.56.0
to0.56.1
, failed, waited for the new release.0.56.0
to0.57.0
, issue is still there, started a project from scratch on top0.57.0
.0.57.0
to0.57.1
, issue is still there.Already followed the manual steps @kelset, and also updated metro to
0.45.6
.Thank me later:
I tried all the solutions presented, but there was success in none at the moment. The Jest or React-Native team could speak on this case.
Confirmed @Amnesthesia 's solution works.
Adding
"postinstall": "rm $( find node_modules -name .babelrc)"
in the scripts section of package.json and then runningnpm install
ORyarn
fixes this issue for me.OK, current hopefully working solution after 55.3 > 57.8: @rszalski’s babel.config.js
+
the transform only required for running tests from within webstorm, from command line the babel config works fine by itself
The closest I’ve gotten to a working Jest with that configuration gives the following errors at various points during the tests:
import
a file after the Jest environment has been torn down.Additionally, it freezes during one of the tests and never completes. Also, there’s nothing specific about the test it freezes on; if I remove that test, it’ll get hung up on another.
I’ve been trying to get this resolved for weeks now. I don’t know what else to try.
The various solutions lead to different results for me but I still haven’t be able to make jest work properly. This is by far the most difficult RN upgrade to date due to the babel changes. Does anyone have any idea who is looking into this? Is it the RN, babel or jest team? It seems like we’re all just locked in a room babbling to ourselves in isolation. 🙂
I would normally just wait but apparently RN 0.58.0 has a fix for the AAPT2 issue and we’re trying to get this resolved since Google will soon not be allowing
android.enableAapt2=false
ingradle.properties
.🌧 When it rains…
I have the same problem too in a full new project with RN 0.58.0-rc.1
Should this be closed? I too am having the same problem, and “it worked eventually” doesn’t seem like much of a solution.
on the babel file .babelrc change this { “presets”: [“module:metro-react-native-babel-preset”] } for this { “presets”: [“react-native”] } it worked for me
New projects I have create use the babel module metro, old projects i already finished uses presets : react-native,i dont know why it changed but i changed the new one for the old one and it worked.