Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest fails to work with Babel7 #6982

Closed
rbiggs opened this issue Sep 15, 2018 · 7 comments
Closed

Jest fails to work with Babel7 #6982

rbiggs opened this issue Sep 15, 2018 · 7 comments

Comments

@rbiggs
Copy link

rbiggs commented Sep 15, 2018

🐛 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

@milesj
Copy link

milesj commented Sep 15, 2018

You have to use babel-core bridge to support Babel 7. https://github.com/facebook/jest/tree/master/packages/babel-jest#usage

@SimenB
Copy link
Member

SimenB commented Sep 15, 2018

@milesj is correct 🙂

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@SimenB SimenB closed this as completed Sep 15, 2018
@yvele
Copy link

yvele commented Sep 17, 2018

@milesj ok for bridge.. but why?

PS: @SimenB Google is redirecting here.. so maybe we can add some explanation.. this is frustrating for many people

@milesj
Copy link

milesj commented 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.

@yvele
Copy link

yvele commented Sep 17, 2018

@milesj Thanks that makes sense. Reading #6949 I understand that jest will soon be upgraded fully with Babel 7 😉

@rbiggs
Copy link
Author

rbiggs commented 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"
}

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants