timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.8k stars 424 forks source link

TypeError: Cannot set property 'runtimeChunk' of undefined #569

Closed MassMessage closed 2 years ago

MassMessage commented 3 years ago

I do need to install react-app-rewired module in the project. However, the current version tunrned into conflict with webpack module. So I went to install the next version:

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

but when I run: react-app-rewired start I get the error:

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.

the config-override.js looks like this:

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;
  },
};

How do I fix this?

timarney commented 2 years ago

This looks like a config issue vs an issue with this repo - please update to the latest and we'll re-open as needed.