webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find mo
Posted 山水一程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find mo相关的知识,希望对你有一定的参考价值。
- webpack报错:
Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module ‘babel-preset-env‘ from ‘...‘ - Did you mean "@babel/env"?
原因:
babel-core和babel-preset-env依赖被替换为@babel/core和@babel/preset-env,因为新版本的Babel7中对官方提供的依赖使用了命名空间@babel
npm install babel-loader babel-core babel-preset-env --save-dev
npm install babel-loader @babel/core @babel/preset-env --save-dev
解决:
在.babelrc文件或在webpack.config.js文件中,将原来的env
替换为@babel/preset-env
// .babelrc
{
"presets": [
["env",
{
"modules": false
}
]
]
}
// webpack.config.js
module: {
rules: [
{
test: /.js$/,
exclude: /(node_modules)/,
use: {
loader: ‘babel-loader‘,
options: {
presets: [‘env‘, { modules: false }]
}
}
}
]
}
- babel官方:https://babeljs.io/docs/en/babel-preset-env#browserslist-integration
以上是关于webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find mo的主要内容,如果未能解决你的问题,请参考以下文章
Module build failed: Error: Cannot find module 'file-loader'
blucesun 解决npm报错:Module build failed: TypeError: this.getResolve is not a function
webpack中Module build failed: Unknown word (2:1)
全局安装的 webpack运行时 报错 Error: Cannot find module 'webpack' ......
Webpack:ES6 语法给出了 Module build failed: SyntaxError: Unexpected token