React / Webpack-从Webpack 1迁移到4,无效的配置对象

时间:2019-04-22 05:37:00

标签: javascript node.js reactjs webpack

已经有一个帖子的问题与我的相似,但是其解决方案对我没有帮助: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

(对码本感到抱歉,编辑者诅咒了语法)

我的package.json-https://jsonblob.com/75e454a8-64bf-11e9-acbe-8b4a2e832cd1

我已经尝试将postsssmodules转移到plugins,但是错误仍然相同。

老实说,我参加了几次Webpack研讨会,但是我仍然不了解我在这段代码中做错了什么。我将非常感谢您的任何建议或帮助!

1 个答案:

答案 0 :(得分:1)

第一个问题是通过删除postcss中的default.config声明解决的

此问题解决了第二个问题:configuration.module has an unknown property 'loaders'

第三个问题通过将default.config中的“ modulesDirectories”重命名为“ modules”来解决