欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wabpack 配置babel报错问题解决

程序员文章站 2024-03-26 12:20:11
...

当我们运行 npn run dev 时babel报错,这是因为babel-loaderbabel对应的版本需要一致。

ERROR in ./src/js/index.js
Module build failed (from ./node_modules/_babel-[email protected]8.1.0@babel-loader/lib/index.js):
Error: Cannot find module '@babel/core'
Require stack:
- E:\web\webpack\04study\01study\node_modules\_babel-[email protected]8.1.0@babel-loader\lib\index.js
- E:\web\webpack\04study\01study\node_modules\_loader-[email protected]2.4.0@loader-runner\lib\loadLoader.js
- E:\web\webpack\04study\01study\node_modules\_loader-[email protected]2.4.0@loader-runner\lib\LoaderRunner.js
- E:\web\webpack\04study\01study\node_modules\[email protected]4.43.0@webpack\lib\NormalModule.js
- E:\web\webpack\04study\01study\node_modules\[email protected]4.43.0@webpack\lib\NormalModuleFactory.js- E:\web\webpack\04study\01study\node_modules\[email protected]4.43.0@webpack\lib\Compiler.js
- E:\web\webpack\04study\01study\node_modules\[email protected]4.43.0@webpack\lib\webpack.js
- E:\web\webpack\04study\01study\node_modules\_webpack-dev-[email protected]3.11.0@webpack-dev-server\bin\webpack-dev-server.js
 babel-[email protected]8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-[email protected]7'.
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (E:\web\webpack\04study\01study\node_modules\_babel-[email protected]8.1.0@babel-loader\lib\index.js:10:11)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)

既然版本要一直,那么我们对应的解决办法就会有两种让两者版本一致:

1、降低babel-loader版本:
npm i babel-core babel-[email protected]7 babel-preset-env -D
2、升级babel到最新版本版本
npm i @babel/core babel-loader @babel/preset-env -D