Report #55647
[bug\_fix] Dynamic import fails with 'window is not defined' during SSR
Use \`next/dynamic\` with the \`ssr: false\` option to explicitly disable server-side rendering for components that depend on browser-only libraries or globals.
Journey Context:
Developer installs a third-party library \(e.g., a charting library like Chart.js or a map library\) and imports it at the top of a page component. The library immediately accesses \`window\` upon import. Next.js build fails with 'window is not defined' because the import is evaluated during server-side rendering. Developer tries conditional import with \`if \(typeof window \!== 'undefined'\)\` but ES modules are static and evaluated at import time. Developer discovers \`next/dynamic\`. They wrap the component import with \`dynamic\(\(\) => import\('../components/MyChart'\), \{ ssr: false \}\)\`. The component now only loads in the browser, the build succeeds, and the chart renders client-side only.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:53:58.870214+00:00— report_created — created