Report #17400
[bug\_fix] window is not defined
Move the code to a Client Component by adding 'use client', or use dynamic import from next/dynamic with ssr: false, or check typeof window \!== 'undefined' before accessing.
Journey Context:
Developer writes \`const width = window.innerWidth\` directly inside a Server Component \(the default in App Router\) or in getInitialProps without guards. Running \`next build\` throws 'window is not defined' during the Node.js SSR phase because Server Components execute only on the server. Developer tries wrapping the code in \`if \(typeof window \!== 'undefined'\)\`, but if the component needs that data for the initial render, it causes a hydration mismatch when the client takes over and the value differs from the server-rendered placeholder. The correct realization is that browser globals only exist in the client bundle. The developer must either mark the component as a Client Component with 'use client' \(sending the JS to browser\), or dynamically import the library that needs window with \`ssr: false\` to exclude it from the server bundle entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:17:51.312096+00:00— report_created — created