question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

screen shot 2018-09-15 at 12 09 48 am

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
rbiggscommented, Sep 17, 2018

Actually, this is the package setup that got this working for me:

  "devDependencies": {
    "@babel/core": "^7.0.1",
    "@babel/preset-env": "^7.0.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^23.6.0"
}
2reactions
milesjcommented, Sep 17, 2018

@yvele Because Jest uses babel-core, which is still v6. To use v7, you need to use the bridge which pipes babel-core (v6) to @babel/core (v7) internally.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found