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

babel-jest plugin & babel 7 incompatibility #5525

Closed
alechp opened this issue Feb 11, 2018 · 13 comments
Closed

babel-jest plugin & babel 7 incompatibility #5525

alechp opened this issue Feb 11, 2018 · 13 comments

Comments

@alechp
Copy link

alechp commented Feb 11, 2018

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:
screen shot 2018-02-11 at 11 19 42 am

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"
          }
        }
      ]
    ]
  }
@thymikee
Copy link
Collaborator

See the docs on using Jest with Babel 7: https://facebook.github.io/jest/docs/en/getting-started.html#using-babel

@alechp
Copy link
Author

alechp commented Feb 11, 2018

Package usage isn't up to date with repo

Getting Started * Jest
screen shot 2018-02-11 at 2 35 07 pm

npm/babel-jest does not include this warning:
screen shot 2018-02-11 at 2 27 00 pm

(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.

@thymikee
Copy link
Collaborator

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).

@alechp
Copy link
Author

alechp commented Feb 12, 2018

Okay. Check this out: babel-jest-comparison

@SimenB
Copy link
Member

SimenB commented Feb 12, 2018

@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"

@alechp
Copy link
Author

alechp commented Feb 12, 2018

@SimenB I have to install both @babel/core & babel-core ?

@rickhanlonii
Copy link
Member

Correct, see #4557

Notice that babel-core and @babel/core are in both the package usage and the repo

@alechp
Copy link
Author

alechp commented Feb 12, 2018

I see. Thanks for clarifying, @rickhanlonii

I'll stick with babel-7-jest in the meantime.

@xlijun
Copy link

xlijun commented May 27, 2018

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.

@wmertens
Copy link
Contributor

wmertens commented Jul 27, 2018

So I installed babel-core@bridge and I still get babel-core from jest-config and jest-runtime:

$ npm ls babel-core
proj@0.0.1 /path/proj
├── babel-core@7.0.0-bridge.0
└─┬ jest-cli@23.4.1
  ├─┬ jest-config@23.4.1
  │ └─┬ babel-core@6.26.3
  │   └─┬ babel-register@6.26.0
  │     └── babel-core@6.26.3
  └─┬ jest-runtime@23.4.1
    └── babel-core@6.26.3

maybe -config and -runtime should declare babel-core as a peerDependency?

@DanielJoyce
Copy link

Same issue. Jest is leading to mixed babel version installs.

@DBosley
Copy link

DBosley commented Sep 6, 2018

Not sure why this issue was closed, but here's an open issue for the same problem: #6913

@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

8 participants