question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reuseExistingChunk option does not respect webpackChunkName

See original GitHub issue

Bug report

What is the current behavior?

Webpack 5 does not seem to respect the splitChunks.cacheGroups.{cacheGroup}.reuseExistingChunk option when handling chunks named with webpackChunkName, resulting in the custom name being overridden by the cache group name.

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

See my minimal reproduction repo here showcasing example builds in v4 and v5. v4 behaves as expected while v5 (from what I can tell) incorrectly names one of the async chunks.

The configs in webpack-4 and webpack-5 should be identical besides a few version-specific changes around cleaning and disabling default cache groups. @formatjs/intl-datetimeformat is used as an arbitrary example to illustrate dynamically importing two modules, one of which meets the cache group size threshold.

What is the expected behavior?

Webpack v5 matches the previous behavior from v4 where reuseExistingChunk: true results in named chunks not being affected by split chunk cache groups (even if they satisfy a group’s test). In the case of the specific example above, both async chunks should be named with their custom webpackChunkNames rather than one using the lib cache group hash.

I may be misinterpreting the expected behavior here, though it does seem like there is a change between v4 and v5. Perhaps I missed something in the migration guide?

Other relevant information: webpack version: 5.36.2 (4.46.0 when comparing with webpack 4 behavior) Node.js version: 14.16.0 Operating System: macOS 10.15.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, May 19, 2021

Yep, there is no bugs, reuseExistingChunk means you already have name for chunk(s), so naming will not work here

0reactions
chrissantamariacommented, May 19, 2021

@alexander-akait sounds good! Ended up finding a workaround for my specific use case but this example helps show some of the differences in Webpack 5. This doesn’t look like a bug so I’m okay closing this issue if you’d like.

Read more comments on GitHub >

github_iconTop Results From Across the Web

what reuseExistingChunk: true means, can give a sample?
The option reuseExistingChunk tells SplitChunks plugin to do additional lookup within existing chunks of current cachingGroup and try not to ...
Read more >
Webpack 5 release (2020-10-10)
A Chunk ID is determined by the chunk's content. So you no longer need to use import(/* webpackChunkName: "name" */ "module") for debugging....
Read more >
Webpack v4 chunk splitting deep dive | Chris Claxton's Blog
The 'vendorSplit' cacheGroup creates chunk for each node module, but still respecting minSize so that we do not end up with too many...
Read more >
webpack/webpack - Gitter
Hopefully that makes sense, but I'm wondering if perhaps this data is somehow available in the filename option (function) but not sure if...
Read more >
Fixing WebpackChunkName for Dynamic Imports - Time to Hack
Are the Webpack Magic Comments webpackChunkName not effective and working with Babel? See how to Fix it and Tips to avoid related problems....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found