-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inevitable unhandled Promise rejection due to failure of prefetch #14115
Comments
You can solve this on your application side |
@alexander-akait I think I did the best in the application code in the repro. All application-side Promises have proper error handling. Do you mean that you don't think this is a problem of Webpack runtime? Then I will bring a bug report to mini-css-extract-plugin side. |
Hey, do I have a chance of second opinion? |
You already doing this using: import("./split.js").catch((err) => {
console.error("import failed", err)
}) I don't see any problems with logic here, if you have |
oh, I see, do you want to catch... |
Interesting case, can you provide more information why you need to catch this? If something was not loaded it can break the application logic, so we prefer to throw an error always in this case |
Maybe related webpack-contrib/mini-css-extract-plugin#802 (regarding logic - |
Thank you for noticing 😃 I prepared another example that is less self-contained but is closer to actual situation. Sorry, I should have presented this from first. https://github.com/uhyo/webpack-prefetch-rejection-repro-2
So when The actual problem we're facing is that this unhandled rejection error is recorded in our error logging facility and we can't suppress the error (expect for letting the error happen but not sending it). Error being thrown is fine, but inevitable unhandled Promise rejection is not great I think 😢 |
I will look at this in near future, sorry for delay |
@uhyo Interesting case, we decided - if something cannot be loaded, it should interrupt the application (related, but not the same webpack-contrib/mini-css-extract-plugin#802). Just interesting - how it happens? In theory you can use dirty workaround, put:
in I don't have strong opinion here, on the one hand you are right - you should have ability to catch, on the other hand why, it was failed, don't think you can load it again. But there is case when you can load fallback. Can you provide information why you need this, what is the real case? |
@alexander-akait thank you for your investigation!
Our use case is error logging. Failure of CSS chunk loading may happen, and we properly handle the error (we give up loading that resource and show a nice error page to the user). However, our error logging facility (namely Sentry) still logs it as “uncaught runtime error” because of the unhandled Promise rejection reported here, which still happens even though we We could set up the error logging facility so that we ignore “loading CSS chunk failed” errors, but we consider it as another dirty workaround. Recently unhandled Promise rejections are considered a sort of uncaught runtime errors; for example, Node.js changed the default setting to terminating the process as soon as an unhandled Promise rejection happens. Therefore, we want to remove the root cause of unhandled Promise rejections whenever possible. I hope this answers your question 🥺 |
Sounds reasonable, marked as bug, feel free to send a fix |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
bump |
I've got the exact same use-case as @uhyo. These errors are finding their way into my Sentry logs and spamming me. Not really sure what causes them because all the ones I've seen, I try going to the URL and it does exist. Perhaps some race condition when I deploy a new version of the app or their browser is cancelling the request? Regardless, a way to catch them so I can handle them better would be nice. FWIW, here's what I see: |
@vankop Can you look at this? |
So.. if you try to do "inner" prefetch ( e.g. in case entrypoint => When code execution will reach I understand that you want to deduplicate errors in Sentry (or other observability tool). However, there is scenario when prefetch fails, but chunk never was requested (no |
@vankop So I understand that prefetch failure cannot always be tied to Currently there is no way of handling failure of prefetch which leads to inevitable error logs on Sentry. How about adding an official way of handling prefetch errors? |
you can use
this will be webpack specific syntax that we trying to avoid.. |
@vankop |
@alexander-akait catch works fine index.js console.log("Hello, world!")
import("./split.js").catch((err) => {
console.log("import failed")
}) split.js console.log("This is split chunk");
import(/* webpackPrefetch: true */"./split2.js").catch((error) => {
console.log("import2 failed!");
}) split2.js console.log("prefetched chunk") after compile just remove |
right now there is a bug that |
Bug 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
npx webpack
.index.html
.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 byimport(...).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:
The text was updated successfully, but these errors were encountered: