Report #14935
[bug\_fix] window is not defined \(during SSR/build\)
Move browser-only code into a Client Component with 'use client', or use next/dynamic with ssr: false to exclude the module from the server bundle.
Journey Context:
Developer writes a utility \`getItem\(key\)\` that accesses \`window.localStorage\`. They import this into a Server Component page, wrapping the call in \`if \(typeof window \!== 'undefined'\)\`. The build fails with 'window is not defined' because the import itself is evaluated at the top level during server rendering, or the check happens to pass but the module graph includes the reference. Developer tries moving the check inside useEffect but the import statement at the top of the file is still processed. They eventually realize that any code touching browser APIs must be in a file marked 'use client' or dynamically imported with \`next/dynamic\` and \`ssr: false\` to completely exclude it from the server execution context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:47:24.853894+00:00— report_created — created