codestates / BanThing

🍔배달비를 BanThing하는 구인 플랫폼입니다.
0 stars 2 forks source link

[Error Handling] window is not defined nextjs #201

Open tmdqls2257 opened 2 years ago

tmdqls2257 commented 2 years ago

어떤 에러인가요?

에러 핸들링 방법

즉, server-side에서 먼저 실행 되고, 그 후에 client-side에서 실행된다. window는 client-side에만 존재한다. 고로 React Component내에서 window를 사용하고 싶다면 componentDidMount내에 코드를 작성해야한다.

if (typeof window !== 'undefined') {
  require('the-lib');
}

에러 핸들링을 위해 참고한 레퍼런스 링크