-
개인프로젝트 과제 에러1카테고리 없음 2023. 4. 19. 21:15
Cannot destructure property 'basename' of 'react__WEBPACK_IMPORTED_MODULE_0__.useContext(...)' as it is null. TypeError: Cannot destructure property 'basename' of 'react__WEBPACK_IMPORTED_MODULE_0__.useContext(...)' as it is null. at LinkWithRef (http://localhost:3001/static/js/bundle.js:40481:5) at renderWithHooks (http://localhost:3001/static/js/bundle.js:25970:22) at updateForwardRef (http://localhost:3001/static/js/bundle.js:28541:24) at beginWork (http://localhost:3001/static/js/bundle.js:30588:20) at HTMLUnknownElement.callCallback (http://localhost:3001/static/js/bundle.js:15562:18) at Object.invokeGuardedCallbackDev (http://localhost:3001/static/js/bundle.js:15606:20) at invokeGuardedCallback (http://localhost:3001/static/js/bundle.js:15663:35) at beginWork$1 (http://localhost:3001/static/js/bundle.js:35537:11) at performUnitOfWork (http://localhost:3001/static/js/bundle.js:34784:16) at workLoopSync (http://localhost:3001/static/js/bundle.js:34707:9)
멀쩡하게 강의에서 알려준대로 똑같이 따라서 했는데 위와 같은 에러가 나와서 경로가 문제인지
계속 찾고 구글링 하고 했을때
이 에러는 React에서 useContext를 사용할 때, 해당 context 객체가 초기화되지 않아서 null이 반환되는 경우 발생합니다. 예를 들어, 다음과 같이 createContext를 사용하여 context 객체를 생성하고, 이를 Provider로 감싸지 않은 경우:
라고 하는데 나는 useContext는 프로젝트 전체에 전혀 쓰지도 않아서 더 어이가 벙벙했다.
그러던중 아차 ! 싶어서 확인해본 App.js에 Router.js가 연결도 되어있지 않은걸 발견했고
추측하건데 파일자체가 root로 보내지지 않는데 어떻게 보였겠나 당연히 에러가 뜨지 싶었다.
역시 아무리 찾아도 모르겠는 에러는 처음부터 보는게 맞는 것 같다.