React/Webpack - 从 webpack 1 迁移到 4,配置对象无效
Posted
技术标签:
【中文标题】React/Webpack - 从 webpack 1 迁移到 4,配置对象无效【英文标题】:React/Webpack - Migrate from webpack 1 to 4, Invalid configuration object 【发布时间】:2019-09-11 08:43:34 【问题描述】:已经有一个帖子和我有类似的问题,但它的解决方案对我没有帮助:Webpack error: configuration has an unknown property 'postcss'
我有以下错误:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property 'postcss'. These properties are valid:
object amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions?
For typos: please correct them.
For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
plugins: [
new webpack.LoaderOptionsPlugin(
// test: /\.xxx$/, // may apply this only for some modules
options:
postcss: …
)
]
- configuration.module has an unknown property 'loaders'. These properties are valid:
object defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?
-> Options affecting the normal modules (`NormalModuleFactory`).
- configuration.resolve has an unknown property 'modulesDirectories'. These properties are valid:
object alias?, aliasFields?, cachePredicate?, cacheWithContext?, concord?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls?
-> Options for the resolver
我的production.config.js
-- https://codepen.io/anon/pen/jRpPVM
(对不起,codepen,编辑器诅咒语法)
我的package.json
-- https://jsonblob.com/75e454a8-64bf-11e9-acbe-8b4a2e832cd1
我已经尝试将postsss
从modules
转移到plugins
,但错误依旧。
老实说,我参加了一些 webpack 研讨会,但我仍然不明白我在这段代码中做错了什么。我将非常感谢您的任何建议或帮助!
【问题讨论】:
你在 default.config 中查看了吗 是的,里面声明了帖子 这就是错误所抱怨的,删除后尝试运行 是的,你是对的,它决定了 1 分(满分 3 分),非常感谢! 第三个问题通过将“modulesDirectories”重命名为“modules”解决了,汤姆,你能写一个答案让我投票吗? :) 【参考方案1】:第一个问题通过删除default.config
中的postcss
声明解决了
这个帖子解决了第二个问题:configuration.module has an unknown property 'loaders'
通过将default.config
中的“modulesDirectories”重命名为“modules”解决了第三个问题
【讨论】:
以上是关于React/Webpack - 从 webpack 1 迁移到 4,配置对象无效的主要内容,如果未能解决你的问题,请参考以下文章
React / Webpack - “模块解析失败:意外令牌 - 您可能需要适当的加载程序来处理此文件类型。”