首页 > 其他分享 >Error_ Requires Babel _^7.0.0-0_, but was loaded with _6.26.3_.异常解决

Error_ Requires Babel _^7.0.0-0_, but was loaded with _6.26.3_.异常解决

时间:2022-12-08 09:55:30浏览次数:47  
标签:node cli lib Babel modules but js babel was

使用webpack初始化工程, 写了个简单的js函数, 想将其打包成exe执行, 在build的时候报错

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.
    at throwVersionError (C:\Users\administrator\gen_sign\node_modules\@babel\helper-plugin-utils\lib\index.js:67:11)
    at Object.assertVersion (C:\Users\administrator\gen_sign\node_modules\@babel\helper-plugin-utils\lib\index.js:10:5)
    at C:\Users\administrator\gen_sign\node_modules\@babel\plugin-transform-runtime\lib\index.js:34:7
    at C:\Users\administrator\gen_sign\node_modules\@babel\helper-plugin-utils\lib\index.js:31:12
    at Function.memoisePluginContainer (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:113:13)
    at Function.normalisePlugin (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:146:32)
    at D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
    at OptionManager.mergeOptions (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
    at OptionManager.init (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
    at File.initOptions (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:212:65)
    at new File (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:135:24)
    at Pipeline.transform (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    at transform (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\util.js:50:22)
    at Object.compile (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\util.js:59:12)
    at write (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\dir.js:21:21)
    at handleFile (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\dir.js:43:7)
    at D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\dir.js:61:9
    at Array.forEach (<anonymous>)
    at handle (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\dir.js:59:29)
    at Array.forEach (<anonymous>)
    at module.exports (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\dir.js:69:15)
    at Object.<anonymous> (D:\00-develop\06-nvm\v14.20.0\node_modules\babel-cli\lib\babel\index.js:129:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `babel src -d dist && pkg -t win dist/index.js -o dist/genSign.exe`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\administrator\AppData\Roaming\npm-cache\_logs\2022-12-08T01_25_47_310Z-debug.log

解决方法
先安装babel依赖

npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/plugin-transform-runtime @babel/plugin-proposal-class-properties @babel/plugin-transform-classes browserify
npm install -S  @babel/runtime

配置.babelrc

{
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-transform-runtime",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-transform-classes"
  ]
}

再执行

npm run build

问题解决

附上package.json

{
  "name": "gen_sign",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "node src/index.js",
    "test": "echo \"no test specified\" && exit 1",
    "build": "babel src -d dist && pkg -t win dist/index.js -o dist/genSign.exe"
  },
  "author": "administrator",
  "license": "ISC",
  "dependencies": {
    "@babel/runtime": "^7.20.6",
    "commander": "^9.4.1",
    "crypto-js": "^4.1.1",
    "es6-promise": "^4.2.8"
  },
  "devDependencies": {
    "@babel/cli": "^7.19.3",
    "@babel/core": "^7.20.5",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-transform-classes": "^7.20.2",
    "@babel/plugin-transform-runtime": "^7.19.6",
    "@babel/preset-env": "^7.20.2",
    "browserify": "^17.0.0"
  }
}

标签:node,cli,lib,Babel,modules,but,js,babel,was
From: https://www.cnblogs.com/iminifly/p/16965252.html

相关文章