webpack又報錯:BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.
阿新 • • 發佈:2018-12-13
完整錯誤資訊如下:
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'
[email protected] requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install '[email protected]'. 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 模組的版本的問題,趕緊百度,得一傳送門:
果然是版本的問題,只需要解除安裝原來的8.x的,安裝7.x版本的就可以了:
npm uninstall babel-loader
npm install [email protected]
最後執行,問題完美解決!