0

我确实需要在项目中安装 react-app-rewired 模块。但是,当前版本与 webpack 模块发生冲突。于是我去安装下一个版本:

npm i react-app-rewired@2.0.2-next.0

但是当我运行时:react-app-rewired start我收到错误:

yarn run v1.22.10
warning ..\..\..\package.json: No license field
$ react-app-rewired start
C:\Users\user1\Desktop\merge\editor\config-overrides.js:3
    config.optimization.runtimeChunk = false;
                                     ^

    TypeError: Cannot set property 'runtimeChunk' of undefined
        at Object.webpack (C:\Users\user1\Desktop\merge\editor\config-overrides.js:3:38)
        at Object.<anonymous> (C:\Users\user1\Desktop\merge\editor\node_modules\react-app-rewired\scripts\start.js:22:15)
        at Module._compile (internal/modules/cjs/loader.js:1068:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
        at Module.load (internal/modules/cjs/loader.js:933:32)
        at Function.Module._load (internal/modules/cjs/loader.js:774:14)
        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
        at internal/main/run_main_module.js:17:47
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

config-override.js看起来像这样:

module.exports = {
  webpack: (config, env) => {
    config.optimization.runtimeChunk = false;
    config.optimization.splitChunks = {
      cacheGroups: {
        default: false,
      },
    };

    config.output.filename = "static/js/[name].js";

    config.plugins[5].options.filename = "static/css/[name].css";
    config.plugins[5].options.moduleFilename = () => "static/css/main.css";
    return config;
  },
};

我该如何解决?

4

0 回答 0