|
阅读:5409回复:0
[其它]webpack打包报错 :Invalid configuration object. Webpack has been initialized using a configuration object
问题:
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",
] //写法是有顺序
}
]
}, |
|
|