vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.74k stars 26.94k forks source link

Unhandled Runtime Error: ChunkLoadError #56484

Closed rsheppard-dev closed 12 months ago

rsheppard-dev commented 1 year ago

Link to the code that reproduces this issue

https://github.com/rsheppard-dev/lh-plumbing

To Reproduce

  1. Start application in development.
  2. Refresh page several times.

Or

  1. Load application in production.
  2. 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)

/_next/static/chunks/webpack.js (155:40) Array.reduce __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 - [X] I verified that the issue exists in the latest Next.js canary release ### Provide environment information ```bash 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.
ArianHamdi commented 1 year ago

We have recently encountered some random crashes when changing routes after upgrading to version 13.5.1. I am not sure about the exact cause, but the page becomes stuck during the route change. In Chrome, it displays an 'Aw, snap!' crash error, while Firefox indicates that the site is slowing down your browser.

We are currently deploying on Amplify AWS.

khalilsarwari commented 1 year ago

This is happening for us in production when leaving the landing page for the following resource:

_next/static/chunks/webpack-8147f10d25df47dc.js Request Method: GET Status Code: 404 Not Found

rahulknagori commented 1 year ago

Facing the same issue in production. Only the pages using CMS/revalidate feature crashes. The issue is most probably in server page.tsx files. Everything works fine in local. This happened when I updated the app to the latest 13.5.5 canary version. Reverted the version to 13.4.1 and now everything works fine even in production.

max-mayorov commented 1 year ago

Having the same issue in production...

ArianHamdi commented 1 year ago

I have found the culprit that is causing the error but I don't know how to fix it easily.

My layout is a server component. My header component in layout.tsx is a server component but that includes a client component for my mobile menu as I use useState to manage the state of my menu. If this is a server component there is no issue but then I can't have a mobile menu functioning.

We are on page router

rsheppard-dev commented 1 year ago

I have changed my hosting to Vercel and so far I haven't had the issue. It appears this is a Netlify issue not a Next issue which I'm glad about cause I love Next but this was making it unusable. Hopefully Netlify fix this. Will keep testing my production app and hopefully it carries on working.

johnrackles commented 1 year ago

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

khalilsarwari commented 1 year ago

@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

jesse-mm commented 1 year ago

Same kind of issue here, I have catch-all in my root [...foo] and for me _next assets are not loading but rather loading the catch-all page. Reverted back to 13.5.4 which works for me.

Due to this issue also navigation "crashes" as mentioned earlier in the comments.

enijar commented 1 year ago

@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.

abilal82 commented 1 year ago

Had same issue in localhost. I just delete .next folder restart the application and issue resolved. error occurred when i changed routing hierarchy. now its working fine. NOTE: This is only applied in development mode, I didn't face this sort of issue on production.

patotoma commented 1 year ago

Noticed the same thing as @enijar. The app is trying to load: .../chats/%255BchatId%255D/page-... which results in 404

but if I update the url manually to .../chats/[chatId]/page-... it works

Current version: 13.5.6

timhonders commented 1 year 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/%5Bstorecode%5D/page.js

And it only happens when navigating.

Checked 14.0.0, it still happening

rahul3v commented 1 year ago

Facing the same issue, revert back to v13.5.4

alvarlagerlof commented 1 year ago

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.

rbkayz commented 1 year ago

+1

huozhi commented 1 year ago

Can someone post a reproduction of this? The origin reproduction in the issue description is 404

github-actions[bot] commented 1 year ago

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template for App Router, template for Pages Router), but you can also use these templates: CodeSandbox: App Router or CodeSandbox: Pages Router.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the canary version of next that introduced the issue. Check out our releases, and try to find the first canary release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of next by running npm install next@<version>.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

enijar commented 1 year ago

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:

<Script
  strategy="beforeInteractive"
  src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
/>
jianliao commented 1 year ago

@huozhi Here is a more detail bug reported by me #57829. Please check the Additional context section.

jianliao commented 1 year ago

As a workaround, you can remove beforeInteractive to avoid this issue.

enijar commented 1 year ago

Removing beforeInteractive fixes this issue. This is 100% still a bug as adding beforeInteractive shouldn't cause that behaviour.

omateusanjos commented 1 year ago

Removing beforeInteractive fixes this issue. This is 100% still a bug as adding beforeInteractive shouldn't cause that behaviour.

Bro, you saved our life. Thank you.

gnoff commented 1 year ago

@jianliao thanks for the repro

huozhi commented 1 year ago

We land a fix for #57829 and also the one mentioned related to next/script in v14.0.2-canary.9, please upragde and let us know if your issue is resolved, thanks!

alvarlagerlof commented 1 year ago

I tested the canary locally and can confirm that it the fix works with the Script strategy="beforeInteractive" 🥳

jianliao commented 12 months ago

@huozhi Thanks for the quick fix. I can confirm it works on 14.0.2-canary.10 now.

feliche93 commented 11 months ago

@huozhi I am still getting an error on 14.0.2 and also latest canary next@14.0.3-canary.2:

For some reason 14.0.1 is working without any errors.

Running pnpm dev everything 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:

ChunkLoadError: Loading chunk 3781 failed.
(missing: http://localhost:3000/_next/static/chunks/3781-32a3a102dc80bd51.js)
    at s.f.j (webpack-20ebb4fb329d62fa.js:1:3964)
    at webpack-20ebb4fb329d62fa.js:1:1427
    at Array.reduce (<anonymous>)
    at s.e (webpack-20ebb4fb329d62fa.js:1:1393)
    at 3815-619463d83fe0fd94.js:6:15126
    at 3815-619463d83fe0fd94.js:6:15328
    at t (3815-619463d83fe0fd94.js:6:15531)
(anonymous) @ 3815-619463d83fe0fd94.js:1

When I refresh the route the page loads without any problem, but a tanstack-table client 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.

huozhi commented 11 months ago

@feliche93 please open a new issue with reproduction, thanks

github-actions[bot] commented 11 months ago

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.