next.js: ChunkLoadError (timeout: (chunks/xxx)
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
Binaries:
Node: 16.16.0
npm: 8.11.0
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.2.2
eslint-config-next: 12.1.5
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
Firefox 102.0
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
When a next js project containing static pages is hosted on Vercel (or anywhere I’m guessing) it regularly generate exception related to chunk loading
ChunkLoadError: Loading chunk 3662 failed.
(error: https://xxx.com/_next/static/chunks/29107295-0151559bd23117ba.js)
I looked everywhere for a simple fix for this, it exist in dev mode (simply delete the .next
folder) but nothing for website in production since it’s a caching issue.
Expected Behavior
This should not happen, or generate exceptions
Link to reproduction
https://stackblitz.com/edit/vercel-next-js-ehpskx
To Reproduce
Create a nextjs project with static pages (via getStaticProps
), install Sentry for error tracking and generate trafic
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 40
- Comments: 58 (6 by maintainers)
This error occurs in the production environment and is reported regularly on Sentry.
I dont think this is the problem, at least in my case, because the problematic chuck is accessible after the error has ocurred. For example I get a stacktrace like this in sentry:
If I try to access
https://www.mywebsite.com/_next/static/chunks/707-e73a4e529df34709.js
right after the error has been reported to sentry, it is accessible My guess is that the loading failed but because of another reason, since the file existsupgrading to next v13.5.4 seems to fix the issue for me
We’re (Sentry) looking at filtering these errors out by default since they don’t seem to be actionable. Would this be helpful to y’all?
Also seeing a lot of these errors in sentry (and have been for a long time). It happens when I deploy a new version (NextJS / Vercel).
At first I thought it was related to NextJS Router Cache caching chunks that is removed on new deployments, but the chunks are still accessible via URL as other people have mentioned, so I’m a bit perplexed…
I’m currently on next
13.4.12
, but we’ve had this issue for a long time.Right now we’re deploying new versions during the night and have implemented custom cache busting (i.e. page reload) functionality to mitigate the issue.
It would be great if new deployments seamlessly purges any cache or whatever is causing this issue, so we can confidently deploy changes often without risk of users seeing an error screen.
Problem
this is happening for me as well with dynamic routes (e.g.
app/whatever/[slug]/page.js
) in next.js 13 app router; it always fails to load the chunk for the dynamic route on production.Environment Details
Observations
[slug]
with a static/named route, then it works.page.js
, if i remove the imported component, everything works. dynamically loading the component as suggested in one of the answers, does not help.page-abc123.js:1 ChunkLoadError: Loading chunk xyz failed.
” happens only when the link is accessed directly. if you navigate to the url via a link in the app, it works fine..next
folder, however, it returns 404 when accessed viahttps://.../_next/static/chunks/app/web/tutorial/%5Bslug%5D/page-abc123.js
i even tried setting up the https://vercel.com/templates/next.js/app-directory demo on my server, and it’s reproducible, however, the same issue does not seem to be on, for example, https://app-router.vercel.app/not-found/does-not-exist
Conclusion
i have tried about 5 days looking for a solution, but it has been to no avail. any help would be greatly appreciated!
We encountered the same problem in production. Environment:
We saw that after a deploy the name
https://DOMAIN/_next/static/chunks/webpack-dcd23afe491cce30.js
did not change, even tough it’s content changed. As the file has a long max-age (31536000
) this resulted in the client’s browser using the cached version, which tried to fetch chunks that didn’t exist in the new build. Resulting in the error message:Loading chunk 3572 failed
.Screenshot diff
As a workaround we added the
buildId
to the name of all chunks by modifying the webpack config like so:My problem was with a tailwind class. I was assigning a class after rendering the component. I deleted it and now it works 😃
I dive into same issue today. Reproduced on next: 13.4.19.
Seems next server doesn’t match uri-encoded
[slug]
with existing folder. I have this issue only on linux server. When I am working under mac, I don’t have this problem.I tried to downgrade to next@13.3.4 and issue was fixed.
Seems we can confirm that we have issue with path resolving on static server. At least we have temporary workaround
Has anyone made any progress on this issue? I’m running into the same problem and cannot for the life of me figure out how to resolve this.
I have found a solution, don’t know if it can help you :
When you do a fetch with no-cache, it will fetch a new page and you will no longer have this error again for the specific page.
It works for me…
My application keeps having this problem (with dynamic imports)
Is anyone still having the chunk loading issue after upgrading to 14.0.2 where we had a fix for it or above versions? If you still have the problem with new version, please open a new issue with reproduction that would be helpful for investigating the specific issues you’re encountering. Thanks!
Check #57829 out. Remove
beforeInteractive
could work around this issue.I pretty sure the this error on 13/14 with App dir was caused by this PR - https://github.com/vercel/next.js/pull/54752
Heads up - the change to default ignore these error is live on sentry.io ref: https://github.com/vercel/next.js/issues/38507#issuecomment-1737937921
ref: https://github.com/getsentry/sentry/issues/57458
I’m encountering the same issue while deploying my app to AWS Amplify Hosting.
This issue still occurs in production environment and happens quite a lot using latest NextJS.
I have the same problem, also happening in Chrome and Safari. When this error occurs, the entire screen also fails.
If the user does a super reload (hold down Shift while reloading) it resolves the problem, but there is no way to make the user do a super reload from javascript.
I have the same problem with v14.0.0 App dir, i have a folder […slug] and when i click to a link that take to that folder i got ChunkLoadError: Loading chunk app/[…slug]/page failed. (error: http://localhost:3000/_next/static/chunks/app/%255B...slug%255D/page.js)
If i refresh the page works
It’s not necessarily to do with deploying. I have a NextJS application that was deployed on (and running since) April 28th and I still get Chunk Load Errors almost daily.
i tried this, however, the issue still persists for me unfortunately … my issue is specifically with chunks created for dynamic route javascript files
I fixed the issue in my case:
I had a component that dynamically imported a file in a useEffect (because it is a client-side-only package):
This is what caused the issue for some reason I don’t know.
Now what I’m doing instead is to import the library at the top of the file: import ‘@typebot.io/js/dist/web’ and dynamically load the entire component with next/dynamic:
I have the same issue in production, any solution?