webpack又報錯:BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.

完整錯誤信息如下:

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]
最後運行,問題完美解決!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章