Robert Biggs
Robert Biggs

Reputation: 23

Problems getting Jest to work with Babel 7.0.0

I'm trying to get Jest to work with Babel 7.0.0. I've installed @babel/core and @babel/env, along with the bridge as recommended on the Jest site: https://github.com/facebook/jest/tree/master/packages/babel-jest. However, when I try to run a simple test, I get the following error:

 ● Test suite failed to run

 Cannot find module 'babel-preset-env' from '/Users/me/Desktop/jest-test'
 - Did you mean "@babel/env"?

 at Function.module.exports [as sync] (node_modules/@babel/core/node_modules/resolve/lib/sync.js:43:15)
 at Array.map (<anonymous>)

The documentation from Jest is very minimal about using it with Babel 7.0.0. I set everything up with the Babel bridge as state, so I assumed there my be a bug, especially since Babel 7.0.0 is fairly new. I posted a bug report with the Jest repository, but they closed it saying my problem was not a bug and that I should seek help on StackOverflow.

Here's what my package.json config looks like:

"scripts": {
  "test": "jest --coverage --no-cache"
},
"babel": {
  "presets": [
    "env"
  ]
},
"devDependencies": {
  "@babel/core": "^7.0.1",
  "@babel/preset-env": "^7.0.0",
  "babel-core": "^7.0.0-bridge.0",
  "babel-jest": "^23.6.0",
  "jest": "^23.6.0",
  "regenerator-runtime": "^0.12.1"
}

I have a test repository on Github. Please take a look. Fork it if you like and send me a pull request: https://github.com/rbiggs/jest-test/commits/master

Upvotes: 2

Views: 1509

Answers (1)

Abdulfatai
Abdulfatai

Reputation: 314

Ensure that what you have installed is @babel/preset-env and not @babel/env as you mentioned. Also make this update to your package.json file

//...

"babel": {
  "presets": [
    "@babel/preset-env"
  ]

//...

Upvotes: 4

Related Questions