Couldn't find preset "module:metro-react-native-babel-preset" when running jest
See original GitHub issueDo 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:50
- Comments:46 (2 by maintainers)
Top GitHub Comments
I have found the same problem today. Open the file
.babelrc
, you will find it in the root of the project, and replace:{ "presets": ["module:metro-react-native-babel-preset"] }
to
{ "presets": ["react-native"] }
For your jest configuration, can you also add
transform: { '^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js' }
?