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

Requires Babel "^7.0.0-0", but was loaded with "6.26.3" #6992

Closed
salmankhann opened this issue Sep 18, 2018 · 6 comments
Closed

Requires Babel "^7.0.0-0", but was loaded with "6.26.3" #6992

salmankhann opened this issue Sep 18, 2018 · 6 comments

Comments

@salmankhann
Copy link

#6662

🐛 Bug Report

Followed the instructions on the jest website to install babel-core to work with Babel7, and also looked at #6662 but nothing seems to help.

The following is the Stacktrace

Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

      at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
      at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
      at _default (node_modules/@babel/plugin-transform-runtime/lib/index.js:82:7)
      at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
          at Array.map (<anonymous>)

My package.json looks like this

"devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.1",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-proposal-json-strings": "^7.0.0",
    "@babel/plugin-proposal-numeric-separator": "^7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "@babel/plugin-transform-object-assign": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-loader": "^8.0.0",
    "jest": "^23.4.1",
    "jest-cli": "^23.4.1",
    "jest-trx-results-processor": "^0.0.7"
  },
  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "@babel/runtime": "^7.0.0",
    "babel-plugin-add-module-exports": "^0.2.1"
  }

My .babelrc

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "ie": 11
                },
                "useBuiltIns": "usage"
            }
        ],
        "@babel/preset-react"
    ],
    "plugins": [
        "@babel/plugin-transform-runtime",
        "@babel/plugin-syntax-dynamic-import",
        "@babel/plugin-syntax-import-meta",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-json-strings",
        [
            "@babel/plugin-proposal-decorators",
            {
                "legacy": true
            }
        ],
        "@babel/plugin-proposal-function-sent",
        "@babel/plugin-proposal-export-namespace-from",
        "@babel/plugin-proposal-numeric-separator",
        "@babel/plugin-proposal-throw-expressions",
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-transform-object-assign"
    ]
}

Run npx envinfo --preset jest

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-4750HQ CPU @ 2.00GHz
  Binaries:
    Node: 10.10.0 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.4.1 => 23.6.0
@MSmashal
Copy link

rimraf node_modules
rimraf package-lock.json

"resolutions": { "babel-core": "7.0.0-bridge.0" },
in package.json

install by yarn,it works.

@SimenB
Copy link
Member

SimenB commented Sep 18, 2018

You don't need resolutions, see example https://github.com/facebook/jest/tree/master/examples/babel-7

You're missing babel-jest dependency.
You might need babel.config.js instead of .babelrc depending in your repo

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 18, 2018
@salmankhann
Copy link
Author

salmankhann commented Sep 18, 2018

You are right I was missing babel-jest (although adding resolutions without babel-jest works too). I had it earlier and it wasn't working and I removed it due to one of the recommendations on SO. Weird its working now, but now I have a different compilation error about exports with jest even though it compiles properly with webpack. I'll try creating an issue on SO for that.

I wanted to create this issue on SO instead of here but thought its a bug with jest because I followed the instructions on the site and it wasn't working.

@mbenadda
Copy link

mbenadda commented Sep 27, 2018

If this may help someone: in some setups you might need the bridge resolution.

Notably if you have some files compiled through ts-jest + babel-jest, and others through an explicitly specified babel-jest only (for example a project in TypeScript that imports lodash-es or some non-compiled react native lib).

In our case ts-jest with babelConfig compiled files using babel 7 as intended, but babel-jest specified directly in transform attempted and failed to compile using babel 6.

@ghost
Copy link

ghost commented Jan 9, 2019

I searched on the internet and tried different solutions (attempts). Nothing worked. Among others I also removed package.json and node_modules. What worked is to uninstall babel-jest with having jest as the only module coming from the jest team.
This confuses me because I thought the jest module's responsibility is only parsing test (\(...).+\.test.js\) files. Or does babel the job? Would be a pleasure to enlighten me.
PS: Of course I tried the normal and officially documented way of installation.

{
  (...)
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/preset-env": "^7.2.3",
    "@babel/preset-typescript": "^7.1.0",
    "@types/jest": "^23.3.12",
    "babel-core": "^7.0.0-bridge.0",
    "jest": "^23.6.0",
    "regenerator-runtime": "^0.13.1",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "dependencies": {}
}

@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