webpack: optimization.splitChunks.maxSize throws error or causes build to hang

Bug report

What is the current behavior?

An error is thrown when attempting to use optimization.splitChunks.maxSize or optimization.splitChunks.cacheGroups.{cachegroupname}.maxSize

Example config:

optimization: {
    splitChunks: {
      chunks: "initial",
      //maxSize: 10000,
      cacheGroups: {
        default: false, // disable the built-in groups, default & vendors (vendors is overwritten below)
        vendors: {
          test: /[\\/]node_modules[\\/]/,
          name: "vendors",
          priority: 10,
          //enforce: true, // create chunk regardless of the size of the chunk
          maxSize: 10000
        }
      }
    }
  },

throws the following error:

setup/node_modules/webpack/lib/util/deterministicGrouping.js:168
				leftSize += group.nodes[left].size;
				                              ^
TypeError: Cannot read property 'size' of undefined
    at module.exports (......../minimal-react-webpack-babel-setup/node_modules/webpack/lib/util/deterministicGrouping.js:168:35)
    at compilation.hooks.optimizeChunksAdvanced.tap.chunks (......../minimal-react-webpack-babel-setup/node_modules/webpack/lib/optimize/SplitChunksPlugin.js:797:23)

Setting maxSize at the splitChunks level causes the same error.

Uncommenting the line //enforce: true, removes the error but causes the build to hang.

If the current behavior is a bug, please provide the steps to reproduce.

Clone the following repo: https://github.com/chrisckc/minimal-react-webpack-babel-setup

Follow the instructions in the readme

This error was first spotted in a more complex app, so i found and forked a less complex app repo to verify the bug.

I can’t make the demo repo any simpler because there needs to be enough node modules available to recreate the issue.

What is the expected behavior?

It should create multiple ‘vendors’ chunks each capped at maxSize or as close as possible.

Other relevant information: webpack version: v4.23.1 Node.js version: v8.11.4 Operating System: MacOS 10.13.4 Additional tools: VSCode, mac terminal

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24 (8 by maintainers)

Commits related to this issue

Most upvoted comments

It would be great if the above referenced issue could also be resolved, it would mean no tiny chunks created when using css extraction, solving the tiny chunks issue completely.

Yeah it probably makes sense that enforce doesn’t modify the minSize used for maxSize, but changing that would be a breaking change for v4. I can change it for v5.

Anyway try to avoid using enforce.