I Didn't Know My Code Was Running on Server (ReferenceError: window is not defined)
내 코드가 서버에서 실행된 줄도 몰랐다 (ReferenceError: window is not defined)
My React code crashed with 'window is not defined' in Next.js. Here's why Server Side Rendering (SSR) breaks browser APIs and 3 robust ways to fix it (useEffect, typeof check, Dynamic Import).
c
codemapo
INTERDISCIPLINARY DEV · SEOUL
9. Conclusion: "Where Does My Code Run?"
Wait, window is not defined is the first growing pain for every React dev moving to Next.js.
Encountering this error means your code has started traversing two worlds (Server and Client).
Always ask yourself when writing code:
"Is this line executing on the server, or the browser?"
Mastering this sense makes Next.js strictness feel like a superpower, not a limitation. And you'll gracefully reach for useEffect or dynamic instead of panicking.