Webpack报错Error: Can‘t resolve ‘babel-loader‘

Webpack报错Error: Can‘t resolve ‘babel-loader‘_第1张图片

在控制台中运行命令“webpack”,出现错误:“ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in.........”

解决方法是在控制台输入命令“npm install i -D babel-loader "。在本项目中安装babel-loader依赖后,编译后报错:

 报错信息: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'.
 

报错原因:

babel-loader和babel-core版本不对应所产生的,
babel-loader 8.x对应babel-core 7.x
babel-loader 7.x对应babel-core 6.x

解决过程:

去package.json里面查看你安装的babel-loader和babel-core的版本是否对应

 解决办法:

卸载旧的babel-core 7.x
 


卸载旧的babel-core 7.x :

执行该命令: npm un i -D babel-core

安装babel-core 7.x:

执行命令: npm install i -D babel-core

执行构建: npm run build

Webpack报错Error: Can‘t resolve ‘babel-loader‘_第2张图片

成功!

你可能感兴趣的:(javascript)