Wednesday, October 24, 2018

Couldn't find preset "module:metro-react-native-babel-preset" relative to directory

Configuring Jest in React Native 0.57.0

I'm trying to get a baseline React Native app setup. Unfortunately, I kept running into problems with configuring Jest. When I run yarn test, I'd get this failure:

Error
C:\Users\sapan\Desktop\react native\Hello>npm test

> Hello@0.0.1 test C:\Users\sapan\Desktop\react native\Hello
> jest

 FAIL  __tests__/Home.js
  ● Test suite failed to run

    Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "C:\\Users\\sapan\\Desktop\\react native\\Hello"

      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)      at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
      at new File (node_modules/babel-core/lib/transformation/file/index.js:135:24)
      at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:16)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.402s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

Solution

the jest section of package.json should look like this:

  "jest": {
    "preset": "react-native",
    "transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js" }
  }


"jest": {
"preset": "react-native",
"transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js" }

}













No comments:

Post a Comment