webpack: Split chunk fails to load with undefined hash

Bug report

What is the current behavior?

Certain chunk requests use undefined instead of the hash. Example of the resulting error in chrome:

Uncaught (in promise) Error: Loading chunk 63 failed.
(error: https://{hostname}/app/63.undefined.feasContentHashV1.chunk.js)
    at HTMLScriptElement.i ({appName}.d5b0c78176fe6ff82a0f.bundle.js:1)

The request for chunk 63 looks like this:

https://{hostname}/app/63.undefined.chunk.js

Stepping through the webpack build, it appears as though the function getScriptSrcPath in JsonpMainTemplatePlugin.js (link) creates a mapping of chunk Id to hash. Looking at the result, the entry for the chunk Id 63 is missing entirely, resulting in the undefined hash in the request.

However, looking through the resulting build, there appears to be a valid chunk 63 with a valid hash in the file name. I’m guessing that somewhere along the line, the reference is lost to this chunk?

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

This is somewhat difficult to reproduce, I think its related to the total number of async chunks made by splitChunksPlugin, but I’m not 100% sure. I’m unable to reproduce a build that can do this. please let me now what other information would be useful.

I think this may be related to https://github.com/webpack/webpack/issues/7061 since the behavior sounds similar. However, according to the maintainers that bug was fixed in 4.6.0. Since we are at a later version (4.29.0) I would expect that fix to be included.

What is the expected behavior?

I would expect JsonpMainTemplatePlugin to produce code that has a valid mapping of all chunk Id’s to their respective hashes, and for all requests for chunks to have defined hashes.

Other relevant information: webpack version: 4.29.0 (I also tried linking to a develop build of webpack) Node.js version: v8.11.1 Operating System: MacOS Additional tools:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 35 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @arcanis I think I can fix that… Tomorrow…

I found a reproduction! Can this issue be reopened? The following repository triggers the bug if you follow the instructions:

https://github.com/arcanis/webpack-project-generator

Tough, but fair 😉 I’ll continue trying to isolate the problem.

We have the same problem on a very large project with multiple entries.

It happens especially when we use the splitChunks config in addition to load a specific module both as a lazy import and regular import in the same bundle. Webpack will add the module directly in the bundle, but will still try to lazy load it with an undefined hash.

I’ll try to make a minimal configuration to reproduce this, but it’s quite difficult to pinpoint.

In the chunk filename I was limiting the hash to 6 chars [chunkhash:6], removing that limit and just use [chunkhash] helped me.

...
output: {
...
  chunkFilename: 'chunks/[name].[chunkhash].js',
...
}
...