question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

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:open
  • Created 5 years ago
  • Reactions:50
  • Comments:46 (2 by maintainers)

github_iconTop GitHub Comments

167reactions
fmaso04commented, Sep 14, 2018

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

126reactions
ajcritescommented, Sep 13, 2018

For your jest configuration, can you also add transform: { '^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js' }?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Couldn't find preset "module:metro-react-native-babel ...
dotfiles from a react-native app into my ~/Projects folder. Suddenly my node app was throwing the Couldn't find preset.. error when running jest...
Read more >
Couldn't find preset "module:metro-react-native-babel-preset ...
exports = to the beginning of the file. This fixed my jest issue but broke other eslint plugins for me. Option 2: Add...
Read more >
[Solved]-React Native with Typescript and Jest is broken after ...
[Solved]-React Native with Typescript and Jest is broken after 0.57 Update: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory- ...
Read more >
metro-react-native-babel-preset - npm
Babel preset for React Native applications. ... Start using metro-react-native-babel-preset in your project by running `npm i ...
Read more >
babel/preset-react
With options: { "presets": [ [ "@babel/preset-react", { "pragma": "dom", // default pragma is React.createElement (only in classic runtime) "pragmaFrag": ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found