Jest fails to work with Babel7
See original GitHub issue🐛 Bug Report
A clear and concise description of what the bug is. I have a simple project where I’m using Babel 7.0.0 instead of 6. Jest fails to work with it, saying that it can’t find the “env” preset, even thought it is installed and indicated in the package-based config.
To Reproduce
Steps to reproduce the behavior: My package.json:
"scripts": {
"test": "jest --coverage --no-cache"
},
"babel": {
"presets": [
"env"
]
},
"devDependencies": {
"@babel/core": "^7.0.1",
"@babel/preset-env": "^7.0.0",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.12.1"
}
Expected behavior
Expect the test to run. When I down grade to Babel 6.x it works as expected. When I try to use Babel 7, it fails.
A clear and concise description of what you expected to happen.
When I run npm t
I get the following error:
● Test suite failed to run
Couldn't find preset "env" relative to directory "/Users/rbiggs/Desktop/jest-test"
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (<anonymous>)
Link to repl or repo (highly encouraged)
https://github.com/rbiggs/jest-test
Please provide either a repl.it demo or a minimal repository on GitHub.
Issues without a reproduction link are likely to stall.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS 10.14
CPU: x64 Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHz
Binaries:
Node: 8.11.2 - /usr/local/bin/node
npm: 5.6.0 - /usr/local/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Output from VSCode:
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Babel 7 with jest fail to run redux component testing
Babel 7 with jest fail to run redux component testing ; This usually means that you are trying to import ; g. it's...
Read more >Get Jest working with Babel 7 | Front-end web development
Today I learned how to get Jest to work with Babel 7. Often development involves tool configuration. I have lost many hours to...
Read more >Jest 24: Refreshing, Polished, TypeScript-friendly
We've upgraded to Babel 7 internally for Jest 24, which comes with support for TypeScript projects. That means Jest can support transpiling ...
Read more >babel-jest - npm
Jest plugin to use babel for transformation.. Latest version: 29.3.1, ... Start using babel-jest in your project by running `npm i babel-jest`.
Read more >React + webpack4 + babel 7 (Jest included) - Medium
Having understood the purpose of webpack and babel, let's put them to use in bootstrapping our first react app with them. We'll go...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, this is the package setup that got this working for me:
@yvele Because Jest uses
babel-core
, which is still v6. To use v7, you need to use the bridge which pipesbabel-core
(v6) to@babel/core
(v7) internally.