【问题标题】:React/Webpack - Migrate from webpack 1 to 4, Invalid configuration objectReact/Webpack - 从 webpack 1 迁移到 4,配置对象无效
【发布时间】: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

我已经尝试将postsssmodules转移到plugins,但错误依旧。

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

【问题讨论】:

  • 你在 default.config 中查看了吗
  • 是的,里面声明了帖子
  • 这就是错误所抱怨的,删除后尝试运行
  • 是的,你是对的,它决定了 1 分(满分 3 分),非常感谢!
  • 第三个问题通过将“modulesDirectories”重命名为“modules”解决了,汤姆,你能写一个答案让我投票吗? :)

标签: javascript node.js reactjs webpack


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-02-26
    • 2017-08-23
    • 2018-09-01
    • 2021-04-10
    • 2020-05-28
    • 1970-01-01
    • 2022-01-12
    • 2017-08-20
    • 2017-05-19
    相关资源
    最近更新 更多