Report #100933
[bug\_fix] Window is not defined during SSR in Next.js
Move code that accesses \`window\`, \`document\`, or other browser objects into a \`useEffect\` hook, or use dynamic import with \`ssr: false\`.
Journey Context:
A developer built a chart component using \`window.innerWidth\` to set initial dimensions. When rendering on the server \(SSR\), the build failed with 'ReferenceError: window is not defined'. The root cause: Node.js does not have a \`window\` global. During server-side rendering, the component code runs in a Node environment. The fix: wrap the window-dependent logic in a \`useEffect\` hook, which only runs on the client after hydration. For dynamic import, the developer used \`dynamic\(\(\) => import\('./Chart'\), \{ ssr: false \}\)\` in the page component to defer the entire module to client-side only. The second approach is cleaner for components that are 100% client-only. The error is one of the most common in Next.js apps that migrate from client-rendered frameworks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:48:46.596372+00:00— report_created — created