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.

Babel 7 setup 'was loaded with "6.26.3"'

See original GitHub issue

🐛 Bug Report

The setup suggested in the documentation doesn’t seem to work and triggers the following error message:

$ jest
 FAIL  ./hi.test.js
  ● Test suite failed to run

    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. (While processing preset: "/Users/verekia/Local/Code/minimal-jest-babel-7/node_modules/@babel/preset-env/lib/index.js")

      at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
          at Array.map (<anonymous>)

(inline): 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. (While processing preset: “/Users/verekia/Local/Code/minimal-jest-babel-7/node_modules/@babel/preset-env/lib/index.js”)

To Reproduce

The package.json used is the following:

{
  "name": "minimal-jest-babel-7",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "start": "babel-node consumer.js",
    "test": "jest"
  },
  "babel": {
    "presets": [
      "@babel/preset-env"
    ]
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.52",
    "@babel/node": "^7.0.0-beta.52",
    "@babel/preset-env": "^7.0.0-beta.52",
    "babel-core": "^7.0.0-0",
    "jest": "^23.3.0"
  }
}

Expected behavior

Running jest should be able to run the test, which includes an import statement. The babel-node command of the minimal repo executes the import successfully.

Link to repl or repo (highly encouraged)

Here is a minimal repo: https://github.com/verekia/minimal-jest-babel-7

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 10.1.0 - /usr/local/bin/node
    Yarn: 1.7.0 - ~/.yarn/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.3.0 => 23.3.0 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
SimenBcommented, Jul 10, 2018

The docs says to install babel-jest 'babel-core@^7.0.0-0' @babel/core regenerator-runtime (https://jestjs.io/docs/en/getting-started#using-babel). Doing that (adding babel-jest) makes your reproduction pass.

(note that regenerator runtime is not needed, I honestly don’t remember in which cases it is)

10reactions
ruslanxdevcommented, Oct 14, 2018

I fix this problem with them.

npm i -D jest babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime
// babel.config.js
'use strict';

module.exports = {
  presets: [
    '@babel/preset-env',
    '@babel/preset-react'
  ],
  plugins: [
    '@babel/plugin-transform-modules-commonjs',
    '@babel/plugin-transform-object-assign',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-proposal-object-rest-spread'
  ]
};
// jest.config.js
'use strict';

module.exports = {
    transform: {
        '^.+\\.jsx$': 'babel-jest',
        '^.+\\.js$': 'babel-jest'
    }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Requires Babel "7.0.0-0" but was loaded with "6.26.3"
Test which version you are running with cmd babel -V. If it is not verion 7 or higher npm uninstall babel-cli -g npm...
Read more >
Requires Babel “7.0.0-0” but was loaded with “6.26.3” - GitHub
In a test setup.js file, I was importing babel-register instead of @babel/register . If you feel like your dependencies are updated, ...
Read more >
Requires Babel "^7.0.0-0", but was loaded with "6.26.3"
I'm facing the below build issue. Some of dependencies has babel 6 and some has babel 7. But, when a dependency requires babel...
Read more >
Upgrade to Babel 7
In Babel 6, values passed to Babel directly (not from a config file), were resolved relative to the files being compiled, which led...
Read more >
Babel 6.26.3 keeps getting installed instead of version 7.7
I was trying to install babel-cli , which is a v6 version of Babel. For v7 you have to use the new logic...
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