Report #104260
[bug\_fix] Next.js build failure: "Module not found: Can't resolve '...'" when using dynamic imports with \`next/dynamic\` and incorrect path or missing default export
Ensure the dynamically imported component has a default export and the path is correct. Use \`dynamic\(\(\) => import\('../components/MyComponent'\), \{ ssr: false \}\)\` if the component uses browser APIs. For named exports, use \`dynamic\(\(\) => import\('../components/MyComponent'\).then\(mod => mod.MyComponent\)\)\`.
Journey Context:
I tried to lazy-load a heavy chart library using \`next/dynamic\`. I wrote \`const Chart = dynamic\(\(\) => import\('../components/Chart'\)\)\`. The build failed with "Module not found: Can't resolve '../components/Chart'". I checked the path — it was correct. Then I realized the \`Chart\` component was exported as a named export \(\`export const Chart\`\), not default. I changed the import to \`dynamic\(\(\) => import\('../components/Chart'\).then\(mod => mod.Chart\)\)\`. That fixed the build. I also had issues with SSR: the chart used \`window\`, so I added \`\{ ssr: false \}\` to avoid hydration errors. The key lesson: dynamic imports require default exports unless you use the \`.then\` pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:08:05.847442+00:00— report_created — created