`Chunk.integrate()` can arbitrarily rename entry name chunk

Bug report

I’ve a webpack config with a “server” entry whose chunk name is renamed with the name of a split chunk when using LimitChunkCountPlugin. Then webpackHotServerMiddleware(compiler, { chunkName: 'server', }) fails to retrieve the handler with given chunk name.

What is the current behavior?
webpackHotServerMiddleware, or anything that uses chunk names of chunk that reveived a call to Chunk.integrate() might fail.

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

See example repo: https://github.com/nicolas-cherel/WebpackNameChunkBug

What is the expected behavior?
The entry chunk name should not be renamed.

The following code might not need to override receiving chunk name into the otherChunk name. (given that callee respects chunks hierarchy in calls).

https://github.com/webpack/webpack/blob/master/lib/Chunk.js#L380-L389

Other relevant information:
webpack version: 4.12.0
Node.js version: v8.10.0 // should be irrelevevant here
Operating System: macOS high Sierra
Additional tools: N/A

edit: as discussed bellow you can mitigate the issue using long chunks name to avoid override of short chunk names you want to keep

Author: Fantashit

1 thought on “`Chunk.integrate()` can arbitrarily rename entry name chunk

  1. This is a really nasty bug, which keeps biting us.
    Removing following lines, mentioned by @nicolas-cherel, works in the particular case with LimitChunkCountPlugin({ maxChunks: 1 }):

    webpack/lib/Chunk.js

    Lines 396 to 405
    in
    482ff20

    if (this.name && otherChunk.name) {
    if (this.name.length !== otherChunk.name.length) {
    this.name =
    this.name.length < otherChunk.name.length
    ? this.name
    : otherChunk.name;
    } else {
    this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
    }
    }

    (My takeaway here is that the shortest chunk name wins, even when there’s only one chunk to be created eventually.)

    Sadly, I don’t know much about the chunk architecture to work out a proper solution. I’d be happy to put together a PR, if someone could give me some directions.

Comments are closed.