profile
viewpoint

Ask questionsCouldn't find preset "module:metro-react-native-babel-preset" when running jest

<!-- Before creating an issue please make sure you are using the latest version of Metro, try re-installing your node_modules folder and run Metro once with --reset-cache to see if that fixes the problem you are experiencing. -->

Do you want to request a feature or report a bug? bugreport

What is the current behavior? I updated a react-native codebase from 0.56 to 0.57 and migrated from "babel-preset-react-native": "^2.1.0" to the current version of "metro-react-native-babel-preset". The app itself compiles and runs for iOS and android but all of the jest tests crash immediately on my mac and on our linux ci.

Test suite failed to run
Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/michaelknoch/dev/repos/JestCrashReproduction"

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

  • clone https://github.com/michaelknoch/jest-metro-reproduction
  • npm i
  • npm run test

I created this repo with react-native init. To run Jest we need at leat one file with pattern *.test.js So i ended up running this: react-native init JestMetroCrash --version 0.57.0 && cd JestMetroCrash && touch App.test.js

Its worth to mention that the test suite also breaks when .babelrc with explicit "presets": ["module:metro-react-native-babel-preset"] is provided.

What is the expected behavior? Jest should resolve the preset and transpile files correctly.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system. node v8.11.3 npm 6.4.1 metro latest release

facebook/metro

Answer questions dsaharia

Hey @michaelknoch. I have the following versions:

"react": "16.5.1",
"react-native": "^0.57.1",
...
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"jest": "^23.6.0",
"metro-react-native-babel-preset": "^0.45.0",

And it works just fine. Just had to change my .babelrc to babelrc.js and install babel-core (npm i -D babel-core@bridge).

Thanks a ton, man

useful!

Related questions

ReferenceError: SHA-1 for file [(...).png] is not computed hot 2
i have local javascript library How do i config metro.config.js hot 2
`SHA-1 for file ... is not computed` when using `resolver.resolveRequest` hot 1
metro-config sharedBlacklist regexp without scape "\" hot 1
Follow symlinks? hot 1
`SHA-1 for file ... is not computed` when using `resolver.resolveRequest` hot 1
metro-config sharedBlacklist regexp without scape "\" hot 1
bundleReleaseJsAndAssets slow for react-native 0.60 / node v12 combo hot 1
Error: Cannot find module 'metro/src/DeltaBundler/Worker' hot 1
concurrent builds fail due to shared use of /tmp/metro-cache/ hot 1
metro-config sharedBlacklist regexp without scape "\" hot 1
Minification can break code (but cannot be disabled?) hot 1
Error: Cannot find module 'metro/src/DeltaBundler/Worker' hot 1
RN - Error: jest-haste-map: @providesModule naming collision hot 1
metro-config sharedBlacklist regexp without scape "\" hot 1
Github User Rank List