next.js: Unhandled Runtime Error: ChunkLoadError
Link to the code that reproduces this issue
https://github.com/rsheppard-dev/lh-plumbing
To Reproduce
- Start application in development.
- Refresh page several times.
Or
- Load application in production.
- Occasionally happens when internet connection speed is low or if navigating between routes quickly.
Current vs. Expected behavior
I expect page page to load normally however in development I get this error:
`Unhandled Runtime Error ChunkLoadError: Loading chunk app/(app)/layout failed. (error: http://localhost:3000/_next/static/chunks/app/(app)/layout.js)
Call Stack webpack_require.f.j file:///Users/roy/Documents/Code/lh-plumbing/.next/static/chunks/webpack.js (853:29) <unknown> /next/static/chunks/webpack.js (155:40) Array.reduce <anonymous> webpack_require.e file:///Users/roy/Documents/Code/lh-plumbing/.next/static/chunks/webpack.js (154:67) fn.e /next/static/chunks/webpack.js (391:50) loadChunk node_modules/.pnpm/next@13.5.5-canary.2@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (202:31) preloadModule node_modules/.pnpm/next@13.5.5-canary.2@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (128:0) resolveModule node_modules/.pnpm/next@13.5.5-canary.2_@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (1725:0) processFullRow node_modules/.pnpm/next@13.5.5-canary.2_@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (1796:0) processBinaryChunk node_modules/.pnpm/next@13.5.5-canary.2_@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (1944:0) progress node_modules/.pnpm/next@13.5.5-canary.2_@babel+core@7.22.20_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js (2024:0)`
If I refresh again page loads normally. In production I got a full page of text like this:
0:["8cuD6kwHKIa0es9d4FAUU",[[["",{"children":["(app)",{"children":["__PAGE__",{}]},"$undefined","$undefined",true]}],"$L1",[[],"$L2"]]]] 3:HL["/_next/static/media/e1c529c04de64b40-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 4:HL["/_next/static/media/e7c7dbb62ddcf6fa-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 5:HL["/_next/static/css/09cb01cb14dd5f8d.css","style"] 6:I{"id":90287,"chunks":["272:static/chunks/webpack-153c1757a1b8d488.js","158:static/chunks/40519c47-39d723cc761f5bdf.js","981:static/chunks/981-d0de02e3ea918bed.js"],"name":"","async":false} 7:I{"id":28695,"chunks":["272:static/chunks/webpack-153c1757a1b8d488.js","158:static/chunks/40519c47-39d723cc761f5bdf.js","981:static/chunks/981-d0de02e3ea918bed.js"],"name":"","async":false} 1:["$","$L6",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$L7",null,{}],"templateStyles":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI ........
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
Node: 20.3.1
npm: 9.6.7
Yarn: N/A
pnpm: 8.6.12
Relevant Packages:
next: 13.5.5-canary.2
eslint-config-next: 13.4.19
react: 18.2.0
react-dom: 18.2.0
typescript: 5.2.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure, App Router
Additional context
I am hosting my Next site on Netlify. This error has happened in production on a MacBook Pro and iPhone 13 Pro using Chrome.
I have also had this happen on Safari.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 13
- Comments: 30 (9 by maintainers)
Commits related to this issue
- Work around https://github.com/vercel/next.js/issues/56484 — committed to ystv/badger by markspolakovs 8 months ago
- Upgrade to Next 13.5.7 (#151) * Next 13.5.7 * Dedupe * Desktop E2E unbreaking * Work around https://github.com/vercel/next.js/issues/56484 — committed to ystv/badger by markspolakovs 8 months ago
- Disable beforeInteractive strategy due to issue: https://github.com/vercel/next.js/issues/56484 — committed to ajitnaik/pawsome-fe by deleted user 8 months ago
I think the problem is that the page.js url is double encode
When you url decode:
http://localhost:3000/_next/static/chunks/app/%255Bstorecode%255D/page.js
you get
http://localhost:3000/_next/static/chunks/app/[storecode]/page.js
And it only happens when navigating.
Checked 14.0.0, it still happening
We land a fix for #57829 and also the one mentioned related to
next/scriptin v14.0.2-canary.9, please upragde and let us know if your issue is resolved, thanks!Having the same issue in production…
Removing
beforeInteractivefixes this issue. This is 100% still a bug as addingbeforeInteractiveshouldn’t cause that behaviour.I’ve tried making a reproduction for the issue mentioned in the lower comments here, specifically double encoding of
[and], but I failed. Since there isn’t one in this issue, I would encourage anyone who’s also having this issue to make one and share a repo link for it if you are able to. For is, the issue only appears on soft navigations.As a workaround, you can remove
beforeInteractiveto avoid this issue.@johnrackles’s solution is currently the only fix for this. We were experiencing the exact same issue. The issue we discovered was due to encoded dynamic routes
[locale].This URL was what Next.js was requesting which 404’d: http://localhost:3000/_next/static/chunks/app/%255Blocale%255D/resources/page.js
But manually URL decoding the URL and opening in a new tab correctly resolved the file: http://localhost:3000/_next/static/chunks/app/[locale]/resources/page.js
We were experiencing this issue on next@13.5.6, but downgrading to next@13.5.4 resolved the issue, so there’s definitely been a bug that’s been released in version next@13.5.5 or later.
So we got this error after upgrading to 13.5.5, in development and deployed to vercel in production. Downgrading to 13.5.4 fixed it
Here’s a repro of this error:
https://github.com/enijar/next-load-error-repro
Notice that somehow including this third party script causes the issue:
@feliche93 please open a new issue with reproduction, thanks
Facing the same issue, revert back to
v13.5.4Noticed the same thing as @enijar. The app is trying to load:
.../chats/%255BchatId%255D/page-...which results in 404but if I update the url manually to
.../chats/[chatId]/page-...it worksCurrent version:
13.5.6@huozhi I am still getting an error on
14.0.2and also latest canarynext@14.0.3-canary.2:For some reason
14.0.1is working without any errors.Running
pnpm deveverything works with no errors shown.When I build locally or deploy and navigate from
/to/backlink-prospects(packages/frontend/src/app/(app)/(paid)/backlink-prospects) via a<Link/>component I get the following error:Application error: a client-side exception has occurred (see the browser console for more information).When I check the console, I see the following:
When I refresh the route the page loads without any problem, but a
tanstack-tableclient component is unresponsive, e.g. clicking and everything doesn’t do anything.Let me know if I should open a new issue or can provide any more info.
I tested the canary locally and can confirm that it the fix works with the Script strategy=“beforeInteractive” 🥳
@jianliao thanks for the repro
@huozhi not sure if you guys have seen this yet, but this does seem to be a pretty significant issue (can’t upgrade without it since the site doesn’t load). There is some activity here as well: https://github.com/vercel/next.js/issues/38507