Next.js ReferenceError: `window` / `localStorage` is not defined (SSR)
Browser global accessed during Server Component or SSR pre-render.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Next.js ReferenceError
Platform: JavaScript
Common Root Causes:
- Browser global accessed during Server Component or SSR pre-render.
Interactive Diagnostic Checklist
Verified Solutions:
- Mark interactive components `"use client"` and access `window`/`localStorage` strictly inside `useEffect`.
Safe Diagnostic Command:
Check file for `"use client"` directive and top-level `window` reads
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Browser global accessed during Server Component or SSR pre-render. Recommended diagnostic: `Check file for `"use client"` directive and top-level `window` reads`. Remediation: Mark interactive components `"use client"` and access `window`/`localStorage` strictly inside `useEffect`.
Worked Examples
- Run `Check file for `"use client"` directive and top-level `window` reads` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-nextjs-window-is-not-defined-ssr · Independently verified: 2026-11-25