Report #100993
[bug\_fix] \`ReferenceError: window is not defined\` \(or \`document is not defined\`\) during Next.js build or server render.
Do not access \`window\`/\`document\` during the render pass. For values shown in UI, read them inside \`useEffect\` and store in state, or use \`next/dynamic\` with \`\{ ssr: false \}\` for browser-only components and third-party libraries.
Journey Context:
You add a charting library to a dashboard and import it normally. \`next build\` fails with \`window is not defined\`. You try adding \`'use client'\`, but the error remains because client components are still prerendered on the server. You wrap the chart component with \`next/dynamic\(..., \{ ssr: false \}\)\`; the import is then skipped during SSR and only runs in the browser. For simpler cases like reading \`window.innerWidth\`, you switch to \`useEffect\` with a state variable so the initial server render matches the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:48:31.730495+00:00— report_created — created