解决:Requires Babel “^7.0.0-0“, but was loaded with “6.26.3“

博客介绍了在遇到`Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”`错误时,如何将前端环境的Babel从6升级到7以解决与jest-babel的版本冲突问题。" 113133828,7803483,VTM10.0编码深入解析:compressGOP()与slice编码流程,"['视频编码', 'H.266/VVC', '编码技术', '视频处理', '软件开发']
部署运行你感兴趣的模型镜像

问题:

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 loo
k for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is 
calling Babel.

解决:

cnpm i babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime

原因:

babel将前端环境更新到babel7,jest-babel之前是基于babel6的,执行时候就会报:Requires Babel “^7.0.0-0”, but was loaded with “6.26.3”.

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

> locus_test@1.0.0 dev E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2 > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js 10% 94% asset optimization ERROR Failed to compile with 2 errors 10:34:38 error in (webpack)-dev-server/client?http://127.0.0.1:8080 Module build 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&#39;t mention "@babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "E:\\job\\job-97 全栈\\mg\\活动配置_jenkins_all\\dev2\\ndules\\@babel\\preset-env\\lib\\index.js") at throwVersionError (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:64:11) at Object.assertVersion (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:10:5) at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\preset-env\lib\index.js:197:7 at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:32:12 at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46 at Array.map (<anonymous>) at OptionManager.resolvePresets (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20) at OptionManager.mergePresets (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10) at OptionManager.mergeOptions (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14) at OptionManager.init (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12) at File.initOptions (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\index.js:212:65) at new File (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\index.js:135:24) at Pipeline.transform (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\pipeline.js:46:16) at transpile (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-loader\lib\index.js:50:20) at Object.module.exports (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-loader\lib\index.js:173:20) @ multi (webpack)-dev-server/client?http://127.0.0.1:8080 webpack/hot/dev-server ./src/main.js error in ./src/main.js Module build 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. I nspect the stack trace of this error to look for the first entry that doesn&#39;t mention "@babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "E:\\job\\job-97 全栈\\mg\\活动配置_jenkins_all\\dev2\\node_modules\\@babel\\preset-env\\lib\\index.js") at throwVersionError (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:64:11) at Object.assertVersion (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:10:5) at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\preset-env\lib\index.js:197:7 at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\@babel\helper-plugin-utils\lib\index.js:32:12 at E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:317:46 at Array.map (<anonymous>) at OptionManager.resolvePresets (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20) at OptionManager.mergePresets (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10) at OptionManager.mergeOptions (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14) at OptionManager.init (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12) at File.initOptions (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\index.js:212:65) at new File (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\file\index.js:135:24) at Pipeline.transform (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-core\lib\transformation\pipeline.js:46:16) at transpile (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-loader\lib\index.js:50:20) at Object.module.exports (E:\job\job-97 全栈\mg\活动配置_jenkins_all\dev2\node_modules\babel-loader\lib\index.js:173:20) @ multi (webpack)-dev-server/client?http://127.0.0.1:8080 webpack/hot/dev-server ./src/main.js
09-12
你遇到的错误是典型的 **Babel 版本冲突问题**: ``` Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3" ``` 这意味着你安装的 `@babel/preset-env`(Babel 7+)需要 `@babel/core`,但你的项目中仍然使用了旧版本的 **`babel-core`(Babel 6)**,这会导致 Babel 插件和核心库版本不兼容。 --- ## 🔍 错误原因分析 | 错误部分 | 原因 | |----------|------| | `@babel/preset-env` | 是 Babel 7 的模块 | | `babel-core` | 是 Babel 6 的核心库 | | **冲突** | Babel 7 的插件不能与 Babel 6 的核心库一起使用 | Webpack 使用了 `babel-loader` 来调用 Babel,但加载了不兼容的版本。 --- ## ✅ 解决方案 ### ✅ 第一步:卸载 Babel 6 相关依赖 ```bash npm uninstall babel-core ``` 如果你还安装了其他 Babel 6 的插件,也一并清除: ```bash npm uninstall babel-loader babel-preset-env ``` --- ### ✅ 第二步:安装 Babel 7 的依赖 ```bash npm install --save-dev @babel/core @babel/preset-env babel-loader ``` --- ### ✅ 第三步:更新 `.babelrc` 确保你的 `.babelrc` 是这样的: ```json { "presets": ["@babel/preset-env"] } ``` --- ### ✅ 第四步:确认 `webpack.config.js` 或 `webpack.dev.conf.js` 中的 `babel-loader` 配置 你已经在 `webpack.dev.conf.js` 中添加了如下规则: ```js { test: /\.js$/, loader: &#39;babel-loader&#39;, include: [ path.resolve(__dirname, &#39;../src&#39;), /@sentry/, ], } ``` 确保没有使用 `babel-core` 的引用。 --- ## 🧹 第五步:清除 node_modules 和 lock 文件(重要) 有时候旧版本的依赖仍然被保留,建议你执行以下命令: ```bash rm -rf node_modules package-lock.json ``` 然后重新安装依赖: ```bash npm install ``` --- ## ✅ 第六步:再次运行开发服务器 ```bash npm run dev ``` 此时你应该不会再看到 Babel 版本冲突的错误。 --- ## ✅ 总结 | 操作 | 目的 | |------|------| | 卸载 `babel-core` | 移除 Babel 6 的核心库 | | 安装 `@babel/core` 和 `@babel/preset-env` | 使用 Babel 7 的现代版本 | | 更新 `.babelrc` | 使用 Babel 7 的配置格式 | | 清理 `node_modules` 和 `package-lock.json` | 确保依赖干净 | | 重新安装依赖 | 保证所有模块版本兼容 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值