Altaula
Altaula

Reputation: 784

Jest with Babel ^7.0.0-beta.51 issue

I followed everything you recommended me to make the Babel 7 work with the Jest. I installed the @babel/core and babel-core. Still It does not work.

{
  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.51",
    "@babel/core": "^7.0.0-beta.51",
    "@babel/node": "^7.0.0-beta.51",
    "@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.51",
    "@babel/preset-flow": "^7.0.0-beta.51",
    "babel-core": "^7.0.0-beta.51",
    "jest-cli": "^23.1.0"
  }
}

After yarn jest

yarn run v1.9.0-20180612.1255
$ /Users/m/Desktop/k/node_modules/.bin/jest
 FAIL  packages/services/src/Client/__tests__/Client.js
  - Test suite failed to run

    Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

      at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
      at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
      at _default (node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js:51:7)
      at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
          at Array.map (<anonymous>)

Upvotes: 6

Views: 1569

Answers (3)

user10670108
user10670108

Reputation: 1

yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 regenerator-runtime

https://jestjs.io/docs/zh-Hans/getting-started

Upvotes: 0

Ian Chadwick
Ian Chadwick

Reputation: 1627

Even though the Jest page says it includes babel-jest I found that adding it to my project fixes the problem.

Upvotes: 3

Allan
Allan

Reputation: 83

Saw your question on the Jest GitHub issues -- I think it was you, but I solved it on my end by going through the create-react-app repo and seeing how they integrated Jest. Specifically, the packages/react-scripts/package.json file has what you need.

"@babel/core": "7.0.0-beta.46", "@babel/runtime": "7.0.0-beta.46", "autoprefixer": "8.5.0", + "babel-core": "7.0.0-bridge.0", "babel-eslint": "8.2.3", "babel-jest": "22.4.3",

Add the line with the +, or change what version you have and you should be good.

Upvotes: 4

Related Questions