需要巴别塔“7.0.0-0”,但装载了“6.26.3”

无论我尝试安装什么,都会得到这个错误(巴贝尔智能) ,因为我遵循其他类似的报告。这是堆栈跟踪:

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 (<anonymous>)
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)

还有我的包裹:

{
"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/"
]
}
}

如果你能提供一些建议,我将不胜感激。

57054 次浏览

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

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

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.

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

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

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

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.

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

npm uninstall babel-cli
npm uninstall babel-core

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.

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
  • Delete node modules.
  • Update your devdepdencies to
"devDependencies": {
"@babel/core": "^7.13.10",
"babel-core": "^7.0.0-bridge.0",
........
}
  • npm install
  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

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

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.

What is the output of npm ls babel-core?

enter image description here

This was mine, so I removed babel-cli@6.26.0 and babel-register@6.26.0 from package.json, and installed @babel/cli and @babel/register

It might be a good idea to delete your lock file and rebuild it.