doubleyong
管理员
管理员
  • 最后登录2021-06-18
  • 发帖数1013
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:333回复:0

[其它]webpack打包报错 :Invalid configuration object. Webpack has been initialized using a configuration object

楼主#
更多 发布于:2021-05-12 16:49
问题:
webpack打包报错:Invalid configuration object. Webpack has been initialized using a configuration object


信息如下:

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.module.rules[1] should be one of these:
  ["..." | object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, re
alResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }, ...]





代码如下:
module:{
       rules:[
           {
               test:/\.css$/,
               use:['style-loader','css-loader']    //写法是有顺序
           },
           {
               test:/\.less$/i,
               loader: [
                   // compiles Less to CSS
                   "style-loader",
                   "css-loader",
                   "less-loader",
               ]   //写法是有顺序
           }
       ]
   },






原因:

一般看到现在的错误,通常就是webpack 配置文件中的键名,写错了,不能识别




解决方案:
仔细检查后,发现rules 下面的对象,使用use键,不要用loader; loader 不能识别,在当前的版本中


注:不同版本的写法不一样


修改后代码:
module:{
       rules:[
           {
               test:/\.css$/,
               use:['style-loader','css-loader']    //写法是有顺序
           },
           {
               test:/\.less$/i,
               use: [
                   // compiles Less to CSS
                   "style-loader",
                   "css-loader",
                   "less-loader",
               ]   //写法是有顺序
           }
       ]
   },
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号