본문 바로가기
카테고리 없음

React 컴포넌트에서 TypeError: Cannot Read Properties of Null 에러 분석

by BillyCho 2025. 2. 6.

 

에러가 발생하면 읽기 싫다...

 

귀찮다...

 

 

ERROR
Cannot read properties of null (reading 'style')
TypeError: Cannot read properties of null (reading 'style')
    at toggleDropdown (http://localhost:3000/static/js/bundle.js:3149:12)
    at HTMLUListElement.<anonymous> (http://localhost:3000/static/js/bundle.js:3163:9)

 

 

 

1. 에러 유형을 확인한다

 

TypeError: 잘못된 타입의 값을 사용하려고 한다

 

2. 에러 설명 확인

 

Cannot read properties of null (reading 'style') 

 

3. 에러 발생 위치 확인

 

at toggleDropdown (http://localhost:3000/static/js/bundle.js:3149:12): 에 발생 함수 파일 위치 나타냅니다. 이 경우 toggleDropdown 함수 3149번째 라, 12번째 열에서 에 발생했습니다.

 

 

- 함수로 찾기: toggleDropdown으로 검색 후 에러 확인

- bundle.js의 경우 개발자 도구를 열어 bundle.js 파일에서 확인

*번들된 파일은 sources 탭 이동 후 ./static/js 에서 확인 가능

 

4추가 호출 스택 확인

at HTMLUListElement.<anonymous> (http://localhost:3000/static/js/bundle.js:3163:9):

이 부분은 toggleDropdown 함수가 호출된 위치 나타냅니다. *이벤트 리스가 익 함수로 정의되어 있

 

*함수 정의 부분이 아닌 호출된 위치임