Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requires Babel "^7.0.0-0", but was loaded with "6.26.0"

I have migrated my app to babel 7 beta and everything seems to work except the tests. I think I've read everything out there but I'm still getting this error:

● Test suite failed to run

Requires Babel "^7.0.0-0", but was loaded with "6.26.0". 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-proposal-class-properties/lib/index.js:81:7)
  at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
      at Array.map (<anonymous>)

Test Suites: 8 failed, 8 total

babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-flow"
  ],
  "plugins": [
    ["module-resolver", {
      "alias": {
        "static": "./static",
        "common": "./src/common",
        "data": "./src/data"
      }
    }],
    ["styled-jsx/babel", { "plugins": ["styled-jsx-plugin-sass"] }],
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-syntax-dynamic-import"
  ]
}

devDependencies

  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.49",
    "@babel/core": "^7.0.0-beta.49",
    "@babel/plugin-proposal-class-properties": "^7.0.0-beta.49",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.49",
    "@babel/preset-env": "^7.0.0-beta.49",
    "@babel/preset-flow": "^7.0.0-beta.49",
    "@babel/preset-react": "^7.0.0-beta.49",
    "babel-core": "^7.0.0-0",
    "babel-eslint": "8.2.3",
    "babel-loader": "^8.0.0-beta",
    "babel-plugin-module-resolver": "^3.1.1",
    "clean-webpack-plugin": "^0.1.19",
    "copy-webpack-plugin": "^4.5.1",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    ...

jest.config.js

module.exports = {
  rootDir: '<rootDir>/../../',
  collectCoverageFrom: ['src/**/*.(jsx|js)'],
  moduleNameMapper: {
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/tests/fileMock.js',
  },
  setupTestFrameworkScriptFile: '<rootDir>/tests/setupTests.js',
};

I run it with command:

"test": "jest --config tests/jest.config.js",
like image 340
Tomasz Mularczyk Avatar asked May 31 '18 09:05

Tomasz Mularczyk


People also ask

How do I check my babel version?

You can also check the version of babel-cli by finding the babel-cli folder in node_modules and looking at the version property of the package. json that is at the base of that folder. If babel-cli was installed globally via -g flag of npm install , you could check the version by executing command babel --version .

Can not Resolve Babel loader?

To solve the error "Module not found: Error: Can't resolve 'babel-loader'", make sure to install the babel-loader package by opening your terminal in your project's root directory and running the command npm install -D babel-loader and restart your development server.

What does babel Register do?

By default @babel/node cli and @babel/register will save to a json cache in your temporary directory. This will heavily improve with the startup and compilation of your files. There are however scenarios where you want to change this behaviour and there are environment variables exposed to allow you to do this.


1 Answers

You need to have both babel-core@^7 and @babel/core@^7 along with babel-jest@latest, try adding

yarn add babel-jest babel-core@^7.0.0-0

as mentioned in here https://github.com/facebook/jest/issues/5525

like image 132
Pavel Hasala Avatar answered Oct 06 '22 19:10

Pavel Hasala