Requires Babel "7.0.0-0" but was loaded with "6.26.3"

ReactjsReact NativeBabeljs

Reactjs Problem Overview


Keep getting this error no matter what I tried installing (babel wise) as I follow other similar reports. this is the stack trace:

> error: bundling failed: Error: 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: > "C:\Users\Admin-ESS\Absent\node_modules\@babel\preset-env\lib\index.js") > at throwVersionError (C:\Users\Admin-ESS\Absent\node_modules@babel\preset-env\node_modules@babel\helper-plugin-utils\lib\index.js:65:11) > at Object.assertVersion (C:\Users\Admin-ESS\Absent\node_modules@babel\preset-env\node_modules@babel\helper-plugin-utils\lib\index.js:13:11) > at _default (C:\Users\Admin-ESS\Absent\node_modules@babel\preset-env\lib\index.js:150:7) > at C:\Users\Admin-ESS\Absent\node_modules@babel\preset-env\node_modules@babel\helper-plugin-utils\lib\index.js:19:12 > at C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46 > at Array.map () > at OptionManager.resolvePresets (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20) > at OptionManager.mergePresets (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10) > at OptionManager.mergeOptions (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14) > at OptionManager.init (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12) > at File.initOptions (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\index.js:212:65) > at new File (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\file\index.js:135:24) > at Pipeline.transform (C:\Users\Admin-ESS\Absent\node_modules\metro\node_modules\babel-core\lib\transformation\pipeline.js:46:16) > at Object.transform (C:\Users\Admin-ESS\Absent\node_modules\metro\src\transformer.js:135:5) > at Object.transformCode [as transform] (C:\Users\Admin-ESS\Absent\node_modules\metro\src\JSTransformer\worker\index.js:253:15) > at execMethod (C:\Users\Admin-ESS\Absent\node_modules\jest-worker\build\child.js:92:29) > at process.on (C:\Users\Admin-ESS\Absent\node_modules\jest-worker\build\child.js:42:7) > at process.emit (events.js:180:13) > at emit (internal/child_process.js:783:12)

and my package.json:

{
  "name": "Absent",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-react-native-stage-0": "^1.0.1",
    "jest": "^23.5.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "16.3.1"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "jest"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "@babel/core": "^7.0.0-rc.1",
    "@babel/preset-env": "^7.0.0-rc.1",
    "@babel/preset-react": "^7.0.0-rc.1",
    "jail-monkey": "^1.0.0",
    "prop-types": "^15.6.2",
    "react": "16.3.1",
    "react-native": "^0.55.4",
    "react-native-device-info": "^0.22.4",
    "react-native-elements": "^0.19.1",
    "react-native-firebase": "^4.3.8",
    "react-native-modal": "^6.5.0",
    "react-native-router-flux": "^4.0.1",
    "react-native-size-matters": "^0.1.2",
    "react-native-vector-icons": "^5.0.0",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}

Any pointers would be greatly appreciated here...

Reactjs Solutions


Solution 1 - Reactjs

Test which version you are running with cmd

babel -V

If it is not verion 7 or higher

npm uninstall babel-cli -g
npm uninstall babel-core -g

And

npm install @babel/cli -g
npm install @babel/core -g

If you are using Jest run

npm install babel-core@7.0.0-bridge.0 --save-dev

> Uninstall and reinstall @babel/node solves the problem if you do node development.

Solution 2 - Reactjs

Looks like you need to install babel-core as the docs suggest: https://jestjs.io/docs/en/getting-started#using-babel

yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime

Solution 3 - Reactjs

Sometimes its because you have installed both babel-cli and babel/cli, or babel-core and @babel/core It causes conflicts

So

  1. delete node_modules

  2. remove babel-cli, babel-core from your package.json, keep @babel/core, @babel/cli

  3. npm install

babel-cli conflicts with @babel/cli

bable-core conflicts with @babel/core

Solution 4 - Reactjs

For the ones who still fighting that, 4 days ago Jest v24 released with native support for babel 7. enjoy.

Solution 5 - Reactjs

None of the solutions I found online worked, I fixed it the following way:

  1. Remove jest and @babel/core from package.json (keep babel-core v7 bridge)
  2. Remove node_modules and package-lock.json
  3. npm install
  4. npm install jest @babel/core --save-dev

Solution 6 - Reactjs

From the Babel Docs, I found that there is an issue with the order in which you install the deps.

> Note: Please install @babel/cli and @babel/core first before npx babel, otherwise npx will install out-of-dated babel 6.x.

As per the usage docs. I found that removing both items from package.json and adding them in order, fixed my issue. Bizarre edge case.

Solution 7 - Reactjs

In my case, the issue was caused by upgrading my @babel/core version, while I kept an outdated webpack (and/or webpack-cli, I simply treated them identically in batch) version. I happened to be using a Webpack config file that was webpack.config.babel.js. Webpack seems to deal with this internally by using babel-register (see this SO answer). This was evidenced by my require stack:

at OptionManager.mergePresets (/Users/me/Projects/github-wide-mode/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/me/Projects/my-project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/me/Projects/my-project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at compile (/Users/me/Projects/my-project/node_modules/babel-register/lib/node.js:103:45)
    at loader (/Users/me/Projects/my-project/node_modules/babel-register/lib/node.js:144:14)
    at Object.require.extensions.<computed> [as .js] (/Users/me/Projects/my-project/node_modules/babel-register/lib/node.js:154:7)
                                                                                                 ^^^^^^^^^^^^^^
    at require (/Users/me/Projects/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at WEBPACK_OPTIONS (/Users/me/Projects/my-project/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
    at requireConfig (/Users/me/Projects/my-project/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)

So webpack-cli was calling babel-register – whose version I presume was dictated by the outdated version of webpack-cli – causing it to target an older version of @babel/babel-core than I had installed.

The solution

I uninstalled the webpack and webpack-cli packages, deleted my node_modules/ and package-lock.json, and then did a fresh npm install.

If this doesn't immediately work, I would suggest following the suggestion included in the error:

> Error: 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.

to pinpoint what is causing (what is most likely) the dependency mismatch. I would also recommend deleting entries in your package.json's dependencies (and/or devDependencies) and then reinstalling them at the npm defaulted version, until they play nice with each other. Stripping away non-essential dependencies and resetting default dependencies should eventually work.

Solution 8 - Reactjs

The issue on my side was a conflict between babel-core, imported by babel-register, and @babel/core, required by Babel documentation for latest usage and set as root npm dependency

It seems babel-register has been moved to @babel/register. Babel didn't update docs with the new module name although they did for their cli/core packages

Here is an update of setup babel doc that works for me:

Installation

npm install --save-dev @babel/register

Usage

In your package.json file make the following changes:

{
  "scripts": {
    "test": "mocha --require @babel/register"
  }
}

Solution 9 - Reactjs

It is NOT recommended to install babel globally. It might be that your IDE has recognized your globally installed package and is going based off of that one. Or what is more likely is that you have have packages that conflict with each other. e.g babel-cli conflicts with @babel/cli

> While you can install Babel CLI globally on your machine, it's much better to install it locally project by project.

yarn remove global @babel/cli @babel/core

In project directory...

yarn remove babel-cli 
yarn add @babel/cli @babel/core @babel/node --dev

Solution 10 - Reactjs

you need this 4 packages, that will fix the issue:

 npm install @babel/cli
 npm install @babel/core
 npm install @babel/node
 npm install @babel/preset-env

Solution 11 - Reactjs

I accidentally had a file called .babelrc in my root directory with the following contents:

{
  "presets": ["@babel/preset-env"]
}

After I deleted that file, I no longer got this error when running my gulp command.

Solution 12 - Reactjs

Sometimes, you have a local version, so remove it so that the global version is ran:

npm uninstall babel-cli
npm uninstall babel-core

Solution 13 - Reactjs

  • Delete node modules.
  • Update your devdepdencies to
"devDependencies": {
      "@babel/core": "^7.13.10",
      "babel-core": "^7.0.0-bridge.0",
      ........
}
  • npm install

Solution 14 - Reactjs

  1. Delete node_modules
  2. Update devDependencies to:
"devDependencies": {
      "@babel/core": "^7.13.10",
      "babel-core": "^7.0.0-bridge.0",
}
  1. Install npm again:
    npm install

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRay JonathanView Question on Stackoverflow
Solution 1 - ReactjsYorubaView Answer on Stackoverflow
Solution 2 - ReactjsrgoldfingerView Answer on Stackoverflow
Solution 3 - ReactjsNuOneView Answer on Stackoverflow
Solution 4 - ReactjsIdan GozlanView Answer on Stackoverflow
Solution 5 - ReactjsDominicView Answer on Stackoverflow
Solution 6 - ReactjsJon DombrowskiView Answer on Stackoverflow
Solution 7 - Reactjszr0gravity7View Answer on Stackoverflow
Solution 8 - ReactjsMaxime HelenView Answer on Stackoverflow
Solution 9 - ReactjsneovrView Answer on Stackoverflow
Solution 10 - Reactjsniek tuytelView Answer on Stackoverflow
Solution 11 - ReactjsRyanView Answer on Stackoverflow
Solution 12 - ReactjsStéphane de LucaView Answer on Stackoverflow
Solution 13 - ReactjsKushalSethView Answer on Stackoverflow
Solution 14 - ReactjsHarika PuppalaView Answer on Stackoverflow