Skip to content
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

[NEXT-847] ChunkLoadError only on deployement if using next/dynamic since Next 13.2.4 #47173

Closed
1 task done
Timothee-P opened this issue Mar 15, 2023 · 10 comments · Fixed by #48583
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@Timothee-P
Copy link

Timothee-P commented Mar 15, 2023

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 22.3.0: Mon Jan 30 20:39:35 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8103
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.29.0
    Relevant packages:
      next: 13.2.5-canary.4
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Dynamic imports (next/dynamic)

To Reproduce

I'm working on trying to reproduce this bug with the reproduction-template, but haven't been able till now.
Maybe creating a exemple with multiple chunks will make it work?

Describe the Bug

Since upgrading next from 13.2.3 to 13.2.4, I have a chunkLoadError on my /app pages, which cause hydratation error.
This only occurs on Vercel deployment or after running next build && next start.
No errors/warning if using next dev or during the build.

Here is a screenshot of the errors:
Capture d’écran 2023-03-15 à 19 03 01

After investigation, the issue seam to appear if using dynamic imports via next/dynamic(or React.lazy).
Dynamic import seem to break hydration when importing component with sub-components also used outside the import.
No issue with a simple 'Hello world' dynamic import, or if bypassing next/dynamic on these more complexe components.

Also, in the exemple showed via the screenshot, the file 3845-003ea1aae1221d6c.js doesn't exist in the /.next folder. But .next/static/chunks/3845.a2edb05c0b138330.js does.

Apparently the same error occurred for jinojacob15 (Comment-#46989) and SuttonJack (Comment-#46989), which seems unrelated to the initial issue.

Expected Behavior

No error on deployement, or at least printing an error on next dev or next build

NEXT-847

@Timothee-P Timothee-P added the bug Issue was opened via the bug report template. label Mar 15, 2023
@jinojacob15
Copy link

Faced the same issue

@shuding shuding added the linear: next Confirmed issue that is tracked by the Next.js team. label Mar 17, 2023
@shuding shuding changed the title ChunkLoadError only on deployement if using next/dynamic since Next 13.2.4 [NEXT-847] ChunkLoadError only on deployement if using next/dynamic since Next 13.2.4 Mar 17, 2023
@miriyas
Copy link

miriyas commented Mar 27, 2023

Same here, client-reference-manifest is pointing wrong file.

830-004c10da4a4c61af.js exist, but manifest sees like 830-s0meth1ngwr0ng.js.

When I removed all dynamic imports, problem gone.

@AndreSilva1993
Copy link

AndreSilva1993 commented Apr 11, 2023

Facing the same thing. I have one page being dynamically loaded - using next/dynamic - since it uses the Leaflet library (which tries to access the window object immediately) and it causes this error in a completely different page. If I remove that dynamic import, everything works as expected.

For reproduction cases, if you want, you can use my personal website's source code which is open source - https://github.com/AndreSilva1993/personal-website. After building and running next start, this error occurs on the homepage every time.

@ecomperftest
Copy link

I am facing the same issue too

@jerray
Copy link

jerray commented Apr 17, 2023

Facing the same issue on 13.3.0

@Nickman87
Copy link

Also have the same issue, even in the latest canary 13.3.1-canary.8.
It is not so easy to reproduce it seems as I tried to make a codesandbox, but it just works, so there will be more at play that just a single next/dynamic import.
https://codesandbox.io/p/sandbox/jovial-bogdan-dv2vkl

I currently bypassed it by doing this (just so it does not render serverside):

// import dynamic from "next/dynamic";
// const App = dynamic(() => import("@/admin/App"), { ssr: false });

const Admin: NextPage = () => {
  if (window) {
    const App = require("@/admin/App").default;
    return <App />;
  }

  return null;
};

@miriyas
Copy link

miriyas commented Apr 19, 2023

next@13.3.1-canary.14

Same

shuding added a commit that referenced this issue Apr 19, 2023
This PR corrects the file names of chunks in the flight manifest.
Previously we assume that the chunk file is always named as
`(requiredChunk.name || requiredChunk.id) + '-' + requiredChunk.hash`
and located in `static/chunks`. This isn't always true (see the comment)
especially when a chunk was generated via `import()`. Another mistake
was that we assume that one chunk only generates one file, but it's
actually possible that it depends on multiple files.

This should address many of the "Chunk failed to load" errors.

Closes [#47173](#47173), fixes
NEXT-847
fix #47173
shuding added a commit that referenced this issue Apr 20, 2023
This PR corrects the file names of chunks in the flight manifest.
Previously we assume that the chunk file is always named as
`(requiredChunk.name || requiredChunk.id) + '-' + requiredChunk.hash`
and located in `static/chunks`. This isn't always true (see the comment)
especially when a chunk was generated via `import()`. Another mistake
was that we assume that one chunk only generates one file, but it's
actually possible that it depends on multiple files.

This should address many of the "Chunk failed to load" errors.

Closes [#47173](#47173), fixes
NEXT-847
fix #47173
@miriyas
Copy link

miriyas commented Apr 21, 2023

next@v13.3.1-canary.16

Confirmed fixed, thanks!

@Nickman87
Copy link

Yes, everything works as expected now, thanks!

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants