webpack_The 'mode' option has not been set ...报错

错误详情

The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
webpack 5.16.0 compiled with 1 warning in 1650 ms

原因解析

没有设置webpack的模式,是生产还是开发(production or development)

解决方法

第一种方法

  • package.json中的scripts属性中添加下列语句
"dev": "webpack --mode development", // 开发环境
"build": "webpack --mode production" // 生产环境
  • webpack.config.js中添加mode属性
mode:`development`

(注意:以上是开发模式,如果是生产模式需要写production

  • 执行webpack,打包成功。

第二种方法

直接在终端调用webpack --mode=development或者webpack --mode=production命令来进行开发模式或者生产模式。
开发模式的代码比生产模式更多。

参考链接

错误:WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'product...
webpack打包The 'mode' option has not been set,错误提示

posted @ 2021-01-23 16:49  Syinho  阅读(218)  评论(0编辑  收藏  举报