文章内容

2022/9/22 17:07:39,作 者: 黄兵

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

今天在使用 webpack-cli 打包的时候,出现了如下错误:

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

 - configuration[0].module.rules[1] has an unknown property 'query'. These properties are valid:

   object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFr

agment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }

   -> A rule description with conditions and effects for modules.

出现错误的原因:

query 已经不是 webpack 中有效的键,需要替换为 options
解决方案:
下面是原来代码:
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env'],
},
}
修改之后的代码如下:
{
test: /\.js$/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
}
再次编译,问题解决。

参考资料:

黄兵个人博客原创。
分享到:

发表评论

评论列表