[React] Fail to compile. Module parse failed: Unexpected token Error 해결
‘react-beautiful-dnd’를 활용해 drag and drop을 구현해 보던 중 코드에는 이상이 없는데 계속 Fail to compile. “Module parse failed: Unexpected token” Error가 발생.
처음에 ‘package-lock.json’ file을 삭제하고 다시 npm i 해봤지만 x
구글링 해보니 create-react-app utility로 설치된 react-scripts 버전이 예전 꺼라 ‘optional chainining’을 지원하지 않는다고 한다! (3. 3. 0 버전 이후 지원)
일단 react 버전을 다 업데이트 해주기로 하고 터미널에 아래 입력
npm install react@latest react-dom@latest
npm install react-scripts@latest
업데이트해주려 했지만 node_module에서 empty file 하면서 충돌이 일어나길래
node_module을 삭제하고 npm i 재설치 해준 후 다시 업데이트해주었더니 에러 해결되었다!
정리
- node_module 폴더 전체 삭제하고 npm i로 재설치 해준다.
- npm install react-scripts@latest로 react-scripts를 최신 버전으로 업데이트해준다.
- 문제 해결! ✅
참고
Odyssey Lift-off I: "Module parse failed: Unexpected token" Error
Hi @Raph! I checked for trailing characters in the track.js file and I don’t believe I spotted any. I started from the repo shared in the course (not a blank project). Here is my repo: GitHub - michelletaing/Odyssey-Lift-Off-I Thank you for the help!
community.apollographql.com
몇 달 전 시작해놓은 프로젝트를 다시 시작하려니 오류를 더 겪는 것 같은데 다 경험이니 다 해결하고 넘어가 보자!