728x90
어떤 에러인가요?
- 에러 메시지
$ window is not defined nextjs
에러 핸들링 방법
- Next.js는 universal 하다.
즉, server-side에서 먼저 실행 되고, 그 후에 client-side에서 실행된다. window는 client-side에만 존재한다. 고로 React Component내에서 window를 사용하고 싶다면 componentDidMount내에 코드를 작성해야한다.
if (typeof window !== 'undefined') {
require('the-lib');
}
에러 핸들링을 위해 참고한 레퍼런스 링크
- Memory-It 의 Error Handling 예시입니다.
링크
Next.js "window,document is not defined" 해결하는 법
Next.js 개발환경에서 window object를 사용할 때, document is undefined, Cannot read innerWidth of undefined 등의 에러메세지를 마주할 때가 있다. Next.js…
sumini.dev
728x90
'오류모음' 카테고리의 다른 글
[this 에러] Uncaught TypeError: Cannot read property 'menu' of undefined at insertCoffeeMenu (index.js:13) at HTMLButtonElement.<anonymous> (0) | 2022.05.15 |
---|---|
[Error Handling] 카카오 로그인 시 owner를 판단 못하는 에러 (0) | 2022.03.10 |
[Error Handling] state를 너무 많이 업데이트 할 경우 에러 (0) | 2022.03.10 |
[Error Handling] 로그 아웃상태시 방 만들기를 했을 때 401에러 (0) | 2022.03.10 |
[Error Handling] next.js에서 클릭시 애니메이션을 생성 방법 (0) | 2022.03.10 |