webpact+react报错Invalid configuration object. Webpack has been initialised using a configuration obj

在学习React与Webpack基本配置时遇到问题,报错信息指出配置对象无效,具体为Webpack初始化时使用的配置对象不匹配API。错误源于`module.loaders`属性不再被支持,现在应改为`module.rules`。这是由于Webpack版本升级导致的规则变更。解决方案是将原有的`loaders`配置项替换为`rules`,以适配新版本Webpack的模块规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

React系列学习笔记:1.React与webpack基本配置:https://www.jianshu.com/p/eb2da4fe7f5b   可参考目录分配,但是webpack.config.js配置中loaders写法已不能再使用。


会一直报无效的配置,如下:

F:\node.js\5-3\5-4>webpack

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

 - configuration.module has an unknown property 'loaders'. These properties are valid:

   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?,

 unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCri

tical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }

   -> Options affecting the normal modules (`NormalModuleFactory`).


原因 : webpack版本更新,新的规则改变。

解决:

把module里的那个loaders改成rules

1
2
3
4
5
6
7
8
module: {
 rules: [
        {
        test: /\.scss$/,
        loader: ('style!css!sass')
        }
  ]
},
参考官方文档:

现在的webpack的loader是配置在rule里的

https://doc.webpack-china.org/configuration/module/#module-rules

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值