[ERROR] Module parse failed: Unexpected token

wishwish·2023년 8월 7일
0

React

목록 보기
1/5

CRA 없이 React typescript 프로젝트를 생성하던 도중 에러를 만났다

ERROR in ./public/src/index.tsx 5:65
Module parse failed: Unexpected token (5:65)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

| import App from "./src/App"
| 
> const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
| root.render(
|   <React.StrictMode>

구글링 했을 때 버전 문제, 파일 로더 문제라는 말을 봤지만 버전도 최신, 에러 코드를 봤을 때 파일 문제도 아닌 것 같았다.

webpack.config.js의 바벨 로더에 문제가 있을 것 같아서 살펴보다가

기존 코드
test: /\\.tsx?$/, 

바꾼 코드
test: /\.(ts|js)x?$/,

파일 확장자?에 문제가 있었음을 알 수 있었다.

참고한 사이트

1개의 댓글

comment-user-thumbnail
2023년 8월 7일

공감하며 읽었습니다. 좋은 글 감사드립니다.

답글 달기