Do you want to request a _feature_ or report a _bug_?
Bug
What is the current behavior?
babel-7-jest does work for me.
babel-jest does _not_ work for me.
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
What is the expected behavior?
When I run test suite using babel-7-jest:
When I run test suite using babel-jest:
TypeError: Cannot read property 'loose' of undefined (While processing preset: "/Users/alechp/Code/servexyz/repospace/cli/node_modules/@babel/preset-env/lib/index.js")
All that is required to make these tests pass is toggle the "transform" option in Jest config from "babel-jest" to "babel-7-jest" (note: I have both installed right now for easy swapping, but I have tried executing babel-jest after having removed babel-7-jest from dependencies and clearing cache)
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Relevant dependencies, jest configuration and babel configuration
"devDependencies": {
"@babel/core": "^7.0.0-beta.39",
"@babel/node": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
"babel-7-jest": "^21.3.3",
"babel-jest": "^22.2.2",
"jest": "^22.2.2"
},
"jest": {
"verbose": true,
"bail": false,
"collectCoverage": false,
"modulePathIgnorePatterns": ["sandbox", "node_modules"],
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "9.3.0"
}
}
]
]
}
See the docs on using Jest with Babel 7: https://facebook.github.io/jest/docs/en/getting-started.html#using-babel
Package usage isn't up to date with repo
npm/babel-jest does not include this warning:
(To save you the click, there's no overflow on the MD block either; it truncates after @babel/core)
Note: If you are using babel version 7 you have to install babel-jest with
npm install --save-dev babel-jest babel-core@^7.0.0-0 @babel/core
This still doesn't resolve my issue, but sharing because it might create issues for others who are using old versions NPM instead of Yarn.
Feel free to send a PR with the note. However we don't actively support npm 2.
Also, if the official installation doesn't work on you, send a repo link which shows that, along with tools version you use (e.g. npm).
Okay. Check this out: babel-jest-comparison
@alechp you haven't installed babel-core@^7.0.0-0
which is in the linked documentation.
This diff makes your tests green:
diff --git i/babel-jest/package.json w/babel-jest/package.json
index 397a4eb..5965a04 100644
--- i/babel-jest/package.json
+++ w/babel-jest/package.json
@@ -9,6 +9,7 @@
"@babel/core": "^7.0.0-beta.39",
"@babel/node": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
+ "babel-core": "^7.0.0-0",
"babel-jest": "^22.2.2",
"jest": "^22.2.2"
},
diff --git i/babel-jest/yarn.lock w/babel-jest/yarn.lock
index fcb51ec..096bf57 100644
--- i/babel-jest/yarn.lock
+++ w/babel-jest/yarn.lock
@@ -664,6 +664,10 @@ babel-core@^6.0.0, babel-core@^6.26.0:
slash "^1.0.0"
source-map "^0.5.6"
+babel-core@^7.0.0-0:
+ version "7.0.0-bridge.0"
+ resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
+
babel-generator@^6.18.0, babel-generator@^6.26.0:
version "6.26.1"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90"
@SimenB I have to install both @babel/core
& babel-core
?
Correct, see https://github.com/facebook/jest/pull/4557
Notice that babel-core
and @babel/core
are in both the package usage and the repo
I see. Thanks for clarifying, @rickhanlonii
I'll stick with babel-7-jest in the meantime.
On Windows
npm install --save-dev babel-jest babel-core@^7.0.0-0 @babel/core
fails. Have to use babel-core@^7.0.0-bridge.0
instead.
So I installed babel-core@bridge
and I still get babel-core from jest-config and jest-runtime:
$ npm ls babel-core
[email protected] /path/proj
โโโ [email protected]
โโโฌ [email protected]
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โโโฌ [email protected]
โ โโโ [email protected]
โโโฌ [email protected]
โโโ [email protected]
maybe -config and -runtime should declare babel-core
as a peerDependency?
Same issue. Jest is leading to mixed babel version installs.
Not sure why this issue was closed, but here's an open issue for the same problem: #6913
Most helpful comment
So I installed
babel-core@bridge
and I still get babel-core from jest-config and jest-runtime:maybe -config and -runtime should declare
babel-core
as a peerDependency?