#6662
Followed the instructions on the jest website to install babel-core to work with Babel7, and also looked at #6662 but nothing seems to help.
The following is the Stacktrace
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-runtime/lib/index.js:82:7)
at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at Array.map (<anonymous>)
My package.json looks like this
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.1",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-object-assign": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-loader": "^8.0.0",
"jest": "^23.4.1",
"jest-cli": "^23.4.1",
"jest-trx-results-processor": "^0.0.7"
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1"
}
My .babelrc
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": 11
},
"useBuiltIns": "usage"
}
],
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-object-assign"
]
}
npx envinfo --preset jest System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-4750HQ CPU @ 2.00GHz
Binaries:
Node: 10.10.0 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
jest: ^23.4.1 => 23.6.0
rimraf node_modules
rimraf package-lock.json
"resolutions": {
"babel-core": "7.0.0-bridge.0"
},
in package.json
install by yarn,it works.
You don't need resolutions, see example https://github.com/facebook/jest/tree/master/examples/babel-7
You're missing babel-jest dependency.
You might need babel.config.js instead of .babelrc depending in your repo
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
You are right I was missing babel-jest (although adding resolutions without babel-jest works too). I had it earlier and it wasn't working and I removed it due to one of the recommendations on SO. Weird its working now, but now I have a different compilation error about exports with jest even though it compiles properly with webpack. I'll try creating an issue on SO for that.
I wanted to create this issue on SO instead of here but thought its a bug with jest because I followed the instructions on the site and it wasn't working.
If this may help someone: in some setups you might need the bridge resolution.
Notably if you have some files compiled through ts-jest + babel-jest, and others through an explicitly specified babel-jest only (for example a project in TypeScript that imports lodash-es or some non-compiled react native lib).
In our case ts-jest with babelConfig compiled files using babel 7 as intended, but babel-jest specified directly in transform attempted and failed to compile using babel 6.
I searched on the internet and tried different solutions (attempts). Nothing worked. Among others I also removed package.json and node_modules. What worked is to uninstall babel-jest with having jest as the only module coming from the jest team.
This confuses me because I thought the jest module's responsibility is only parsing test (\(...).+\.test.js\) files. Or does babel the job? Would be a pleasure to enlighten me.
PS: Of course I tried the normal and officially documented way of installation.
{
(...)
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-typescript": "^7.1.0",
"@types/jest": "^23.3.12",
"babel-core": "^7.0.0-bridge.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.13.1",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"dependencies": {}
}
Most helpful comment
rimraf node_modules
rimraf package-lock.json
"resolutions": { "babel-core": "7.0.0-bridge.0" },in package.json
install by yarn,it works.