版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/m0_37750720/article/details/82940625
完整错误信息如下:
ERROR in multi ./app/js/index.js
Module not found: Error: Can't resolve 'babel' in 'E:\works\ES6'
BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.
You need to specify 'babel-loader' instead of 'babel',
see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed
@ multi ./app/js/index.js index[0]
我的配置代码:
module:{
rules:[{
test:/\.js$/,
loader:'babel'
}]
}
翻译下错误信息:
不再允许在使用加载器时省略“-loader”后缀。你需要指定’babel-loader’而不是’babel’…
那好,赶紧加上-loader后缀:
module:{
rules:[{
test:/\.js$/,
loader:'babel-loader'
}]
}
运行,又报错:
ERROR in ./app/js/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '@babel/core'
babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\works\ES6\node_modules\babel-loader\lib\index.js:10:11)
at Module._compile (module.js:652:30)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .js] (E:\works\ES6\node_modules\babel-register\lib\node.js:152:7)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at loadLoader (E:\works\ES6\node_modules\loader-runner\lib\loadLoader.js:13:17)
at iteratePitchingLoaders (E:\works\ES6\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (E:\works\ES6\node_modules\loader-runner\lib\LoaderRunner.js:362:2)
@ multi ./app/js/index.js index[0]
看起来大致试说 babel-loader 模块的版本的问题,赶紧百度,得一传送门:
webpack.config.js配置遇到Error: Cannot find module '@babel/core’问题
果然是版本的问题,只需要卸载原来的8.x的,安装7.x版本的就可以了:
npm uninstall babel-loader
npm install [email protected]
最后运行,问题完美解决!