-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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 v14.2.8 with next/dynamic component breaks app #69720
Comments
Encountered this too. Looking for a resolution |
Hi! Sorry about that -- definitely shouldn't break things like this in a patch release! I'm looking into what's causing this. AFAICT, it's specific to a server component (e.g. In the meantime, as a workaround, try the following: If your module has a default export, there's no need to do // default export - no need to `.then` at all
const TestDynamicComp = dynamic(() => import("../components/Test"), {
ssr: false,
}); (Technically, You only need to do something with the module if you're trying to use a named export: // named export - need to wrap in `{ default: }`
const TestDynamicComp = dynamic(
() =>
import("../components/Test").then((module) => {
return { default: module.TestComp };
}),
{
ssr: false,
}
); I've tested these in your repro and both forms work for me on 14.2.8. |
Technically it's not really doing If you're looking better code splitting with In your case, you might want to move the dynamic component into another client component file. // client-dynamic-compo.js
'use client'
export const TestDynamicComp = dynamic(
() => import("../components/Test").then((module) => module.default),
{
ssr: false,
}
); Then use the // page.js
import { TestDynamicComp } from './client-dynamic-comp'
<TestDynamicComp /> This will have less impact for the future updates and really using the code splitting ability of |
This solution worked for me: #47316 |
This reverts commit 9bb06c5. This was a sort breaking change that could effect using `next/dynamic` in server component, when the imported one is client component. Ideally you shouldn't directly return it due to the property access restriction for client reference. We've already provided related codemod for v15 but this might be a bit surprise for users upgrading to the new patch. Reverted as it's not necessarily part of ESM externals fixes. Fixes #69720
Hey @huozhi 👋
I'm not sure I understand this correctly. const DynamicComponent = dynamic(() => import('./Component'), {
ssr: false,
}); I had some issues with When running the project in dev, I had a 500 with the same error, but the page rendered fine. When I implemented what your message suggests with |
Because I have used |
@borisghidaglia when you use |
Regarding to this issue, I had a fix #69749 to change the behavior back as and release a patch soon. Since the pattern of "using |
This is fixed in patch release 14.2.9, please upgrade Next.js to that version, thanks 🙏 |
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. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/j6yc57
To Reproduce
Current vs. Expected behavior
I expected that next/dynamic component would work since prior to this nextjs version it did
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Available memory (MB): 4102 Available CPU cores: 2 Binaries: Node: 20.9.0 npm: 9.8.1 Yarn: 1.22.19 pnpm: 8.10.2 Relevant Packages: next: 14.2.8 // Latest available version is detected (14.2.8). eslint-config-next: 14.2.1 react: 18.3.1 react-dom: 18.3.1 typescript: 5.5.4 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
create-next-app, Developer Experience, Module Resolution, Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: