Inevitable unhandled Promise rejection due to failure of prefetch
See original GitHub issueBug report
TL; DR: Promise without .catch
here.
What is the current behavior?
If you dynamic-import a chunk and that chunk tries to prefetch another chunk, and that prefetch fails for some reason, you get an unhandled Promise rejection reported even if you are doing proper error handling.
If the current behavior is a bug, please provide the steps to reproduce.
Here is a reproduction repo: https://github.com/uhyo/webpack-prefetch-rejection-repro
- Build by
npx webpack
. - Open
index.html
. - You see an unhandled Promise rejection reported.
The repro includes a custom Webpack plugin (BoomPlugin
) that simulates a failure of loading of accompanying resources. Of course, this is just for easily reproducing the issue; the case I actually faced involved mini-css-extract-plugin trying to load a CSS chunk accompanying main chunk.
What is of note is that all import()
calls included in source code properly handles Promise rejections. The above image shows how a prefetch failure error is handled by import(...).catch
but is still reported as a Promise rejection via another path.
Seems that this unhandled Promise rejection is inevitable; the rejecting Promise is created internally in Webpack runtime and there is no way of preventing that.
What is the expected behavior?
Properly handle the error internally, or provide a way to register a .catch
handler to the internal Promise.
Other relevant information: webpack version: 5.51.1 Node.js version: 14.15.0 Operating System: MacoS Mojave 10.14.6 Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Comments:22 (17 by maintainers)
Top GitHub Comments
You can solve this on your application side
@vankop Can you look at this?