-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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 ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle chunk loading errors that are not triggered by navigation #23612
Comments
Currently you can set |
I get the same error It happens when I click the login button in sidebase/nuxt-auth and then press the back button in window browser, sometimes I get a normal page but sometimes I get the error. I am using nuxt for product level service. I didn't deploy yet but I would like to know and prevent it. |
As you said, I set but chunk error not catched. So I made own my error catch plugin. // plugins/error-handler.ts
exportdefaultdefineNuxtPlugin((nuxtApp)=>{
nuxtApp.hook("app:error",(error,instance,info)=>{
constreoload_error_list=[
"error loading dynamically imported module",
"Importing a module script failed",
"Failed to fetch dynamically imported module",
];
for(constmessageofreoload_error_list){
if(error.message.indexOf(message)>-1){
window.location.reload();
}
}
});
}); It's not real solution but temprory it could help page working properly without all the time manual refresh PS. In my case |
@quroom,do you still use the workaround you provided here and did it solve your issue? I am facing the same issue and I am looking for a fix. |
Yeah. I am using that code still. I haven't seen that chunk error until now after including code that I mentioned. |
This comment was marked as duplicate.
This comment was marked as duplicate.
I too found that a lazy-loaded component would not cause any error and would just silently fail without a retry. I found that the "app:error" hook suggested by@quroomwould not fire. Insteadthe "app:chunkError" hook is needed. essentially replacing the name of the hook in the code above. That hook is not documented onhttps://nuxt /docs/api/advanced/hooks#app-hooks-runtimebut (as that page suggests) itisin the code:https://github /nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L48and so does work when combined withhttps://nuxt /docs/guide/going-further/experimental-features#emitroutechunkerror. The app thendoesreload. However the code above could result in infinite reloads on a network issue (can simulate by simply deleting a chunk) and so I would guess it needs an "attempts" counter in sessionStorage/localStorage and then give up. I assume (?) Nuxt's handler is smart enough to avoid infinite retries. We could look how it does that. |
The code@quroomprovided does in my implementation result in an infinite reload loop so I would advise to use it with caution. |
By the way, are there any other/new fixes available? Because none oof the provided solutions helped me fix the error. |
@maximatically I don't believe the issue itself is fixed, however building on the above example the infinite-reload could perhaps be solved by using Nuxt's own function Fromhttps://nuxt /docs/api/utils/reload-nuxt-appit looks like if/when that's calledagainwithin its default time of 10s, that will be ignored. Something like: exportdefaultdefineNuxtPlugin((nuxtApp)=>{
nuxtApp.hook("app:chunkError",(err)=>{
consterror_list=[
"error loading dynamically imported module",
"Importing a module script failed",
"Failed to fetch dynamically imported module",
];
for(constmessageoferror_list){
if(message.indexOf(message)>-1){
console.error("app:chunkError reloading...");
reloadNuxtApp();
}
}
});
}); |
Sadly this doesn't seem to fix my problems. I think I will leave it for now and once I have time I'll write the nuxt/ui component I'm using from scratch. |
I'm also facing this issue when deploying my new website built with Nuxt 3 + Nuxt UI Pro to Cloudflare. I can load the homepage just fine if I append a query param. I tried the above work-arounds, but no luck. Update:I was able to resolve it for now by totally deleting my Cloudflare page project and redeploying. That's pretty rough... hope this gets fixed soon. |
@danielroewould you be open to receiving a small PR that adds a exportdefaultdefineNuxtPlugin({
name:'nuxt:chunk-reload-navigation-and-lazy',
setup(nuxtApp){
nuxtApp.hook('app:chunkError',()=>{reloadNuxtApp()})
},
}) The PR would also extend docs on this to explain the different trade-offs (eg: One potential improvement to this proposal I already see is renaming the I think this would be useful as many users (see this issue & the many duplicates) seem to encounter the Lazy-chunk error, but don't seem to be comfortable with adding their own If you think this is useful, I'd be happy to open a PR & push it through. Thanks 💯 |
I would! Thank you for the idea. |
Great (: I've opened#28160to implement the proposal. |
Excited to see this finally fixed! 👀 |
Describe the feature
When a chunk has been given a new name during build as it has changed, some clients will try to load the old chunk name. This results in errors like:
TypeError: error loading dynamically imported module:....
Importing a module script failed.
Failed to fetch dynamically imported module:...
With pages this issue gets detected, and the page reloaded which is necessary.
nuxt/packages/nuxt/src/app/plugins/chunk-reload.client.ts
Line 21 in 24c5af3
However, when I other lazy components that aren't pages, they might fail the same way, but there's have no strategy in place for them, nor can I safely tell the page and another lazy component error apart.
Solutions:
I don't think it would be wise to refresh the page on any and all chunk errors (as a lazy component might not be too critical and it's more important to have a smooth ux).
If nuxt cannot resolve this issue universally, perhaps we could come up with a strategy and some documentation to include in the docs.
Original Issue for this feature:#14594 (comment)
Additional information
Final checks
The text was updated successfully, but these errors were encountered: