codestates / codestates/BanThing
[Error Handling] window is not defined nextjs
Open
client
error
solved
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?
- 에러 메시지
```
$ 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 예시입니다.
[링크](https://sumini.dev/issue/000-nextjs-window,document-is-not-defined/)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.