webpack: Provide more info in `ChunkLoadError`
Would it be possible to provide more info in ChunkLoadError, i.e. exact reason of failing?
I have an interesting case where from time to time my chunk is not loaded. When I open devtools
I can see that request for chunk is successful but the chunk is still not loaded. I have implemented retry strategy for these cases but it seems it does not help.
I would like to provide you with minimal working example but unfortunately I am not able to provide one. I think there is something interfering with the webpack code. Maybe some old library or something hence more info in the error or original event attached to the error would be nice to have. Maybe the original event contains more information about failing.
As you can see from the screenshot the bundle loads correctly but it still throws ChunkLoadError hence I try it again 3x but it still fails.
Would it be please possible to attach original event to Error the same way as Error.request is?
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 4
- Comments: 18 (9 by maintainers)
Commits related to this issue
- feat(#16618): add real error message in jsonp evaluation error — committed to aespinolopez/webpack by aespinolopez a year ago
- feat(#16618): add real error message in jsonp evaluation error — committed to aespinolopez/webpack by aespinolopez a year ago
- feat(#16618): check window — committed to aespinolopez/webpack by aespinolopez a year ago
- test(#16618): test jsonp event listeners — committed to aespinolopez/webpack by aespinolopez a year ago
- feat(#16618): use window check — committed to aespinolopez/webpack by aespinolopez a year ago
- fix(#16618): output module without global — committed to aespinolopez/webpack by aespinolopez a year ago
@aespinolopez I think
I think is better
Would also love to see this merged. We are facing some similar issues, where at least from the metrics perspective the number of errors we get is higher than the failed network requests - so we are a bit in the dark of what is going on.
Would be great if we can get some more information in our logs on the reason why chunks failed to load 😃
Hi @alexander-akait I created a reproducible repo for my comment above.
Both the parsing error and webpack chunk error are reported to console and the orignal error should always be displayed by the specificatoin if i understand it correctly. The parsing error will be opaque in case of cross origin scripts and it will log Script Error.
In order to add the original error to ChunkLoadError a global error handler is needed and i don’t know if this is a good idea (i’m open to suggestions but i think it is the only possible implementation) so my suggestion would be to change the error message of ChunkLoadError IF my assumptions are correct:
Webpack reports the error on lib/web/JsonpChunkLoadingRuntimeModule.js:177. This callback is attached to the script onload/onerror handlers and only runs if installedChunks is truthy (only possible truthy value is [res, rej, promise]) meaning the chunk has not load correctly. In this scenario if the handler for the callback is onload the error type is set to missing and i think this is misleading and incorrect because the only possible scenario here is that the script has actually being loaded but an exception was thown during parsing / evaluation otherwise installedChunkData will be 0.
As conclusion i think the log “missing: {url}” should be change to a value like ChunkError: {url}
I faced recently a similar scenario: the error was caused by a syntax error in safari due to a lookbehind regex (not supported in safari). The chunk was downloaded successfully but an exception was triggered during script evaluation and reported by webpack runtime as loading error.
I can share a reproducible example if needed and glad to take a look at it and send a PR!