-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Failed to fetch dynamically imported module "/_nuxt/OpeningHours.CTqYYKGj.js" #26565
Comments
I suspect this is due to new deployments and failing to load a dynamic chunk after a new deployment occurs, which might have invalidating existing public assets. We currently handle chunk loading errors when navigating across routes but we could probably think about whether there is anything we could do when that is a dynamic component import. |
@danielroe is there anything I can do to avoid this crashing in production? did I understand correctly that this is due to the fact that I use Lazy components - i.e. dynamically loaded ones? Or is this an internal issue? |
I can confirm that this issue (and others like it) occurs after a new deployment. This isn't just related to "Lazy Components" as it gives me the "Failed to load dynamically..." message for pages, layouts and middleware modules (chunks) as well. My observations when the error occurs:
|
@michalzaq12 thank you for your observations! So I am using GitHub actions with Azure app service to deploy the app. Will a manual build an deploy via file upload for example help? |
@mikeCrafted it won't help. For now, there is no way to avoid these errors. |
We've also encountered these errors after deployments, which we fixed by triggering page reload on chunk error by adding the following file
I believe Nuxt should handle this internally, as I am sure it is a common problem. |
@meirroth I think this handler is already added by default in Nuxt, see #19086 |
@mikeCrafted From what I understood, and I could be wrong, the built in handler takes care of errors only during route navigation. The plugin I shared above helps with any other chunk loading errors, such as lazy components. |
@meirroth oh, that is interesting! why are you not using |
I see the possibility of an endless reload loop. That's probably why Nuxt doesn't support it internally. |
@michalzaq12 adding a query parameter to the URL would help, right? so that we can tell if a reload was already attempted. |
@mikeCrafted Haven't tried that. I'll give it it a shot now.
@michalzaq12 How so? I haven't encountered any issue in my testing, and got this running in production. |
@mikeCrafted |
@meirroth oh cool, thank you! what production site are you running? |
To avoid most errors:
export default defineNuxtPlugin(nuxtApp => {
const MAX_RETRIES = 2;
const QUERY_PARAM_NAME = 'nuxt_reload_attempt'
// Handle "Failed to fetch dynamically imported module ..." or similar issues
nuxtApp.hook('app:chunkError', () => {
const searchParams = new URLSearchParams(window.location.search);
const currentRetry = Number(searchParams.get(QUERY_PARAM_NAME)) || 0
if (currentRetry < MAX_RETRIES) {
console.log('[nuxt]: Reloading due to chunk error')
searchParams.set(QUERY_PARAM_NAME, (currentRetry + 1).toString())
// Changing the search also causes a refresh
window.location.search = searchParams.toString()
}
})
}) |
@michalzaq12 How so? I haven't encountered any issue in my testing, and got this running in production. |
Duplicate of #23612 |
Doc says that hard reload at the route level is done by default: https://nuxt.com/docs/guide/going-further/experimental-features#emitroutechunkerror. If the idea is to watch for that hook and refresh the window, I believe adjusting the I'm having the same issue. Currently, deploying at Cloudflare Pages; and all cache settings were reviewed. We tried using a similar approach as the proposed plugin; even adding a |
Environment
Reproduction
This is an indeterministic bug in production, I cannot find commonalities when it occurs. Apple users (Safari browser) tend to have it more often. I get a lot of sentry errors and see it in the server logs, but mixed with a lot of correct requests, it works on all my devices and on ones of my colleagues, but according to sentry there are users who experience crashes.
Describe the bug
According to our sentry report, there are regular crashes of the app on many different pages (sometimes on the homepage, sometimes during search etc.), when nuxt fails to resolve a file path and the app crashes.
The majority of logs are fine, but still we see a regular issues popping up in sentry. The components that fail to resolve are also different. They work on all my devices, so I cannot reproduce the error in production. Nor does it occur in development.
We host the app on Azure App Service.
I recently upgraded to the latest nuxt version, where the naming of the chunks was changed, still I saw some logs today that a component with the old naming style could not be imported. I am not opting in for the old one, I switched to the default new one.
Can setting the
builder: 'webpack'
help?I feel like this issue might be related @danielroe ? #21780
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: