Report #80733
[bug\_fix] ReferenceError: window is not defined \(or document is not defined\)
Move any access to window, document, or other browser-only APIs inside a useEffect hook \(which only runs on the client\), or check typeof window \!== 'undefined' before accessing the global, or use dynamic import with ssr: false for heavy browser-only libraries.
Journey Context:
Developer installs a third-party library \(like a charting library or a maps SDK\) that directly accesses window or document when imported. They import it at the top of their component file. Everything works in development mode when navigating client-side, but when they refresh the page or run next build, it crashes with "window is not defined". Developer tries to add a check if \(window\) at the top of the file, but this fails because the import statement itself executes the code. They try to move the logic into useEffect but the import statement at the top still runs during SSR. Eventually, they learn about dynamic imports with ssr: false to exclude the module from server bundles, or they wrap the usage in useEffect with a client-ready flag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T18:06:54.987558+00:00— report_created — created