NodeJS

[React] The “path” argument must be of type string. 문제 해결

Create-React-App 프로젝트를 빌드하거나 개발 환경에서 테스트하는 경우 npm run start 또는 yarn start와 같은 명령어를 사용합니다. 그런데 언제부턴가 아래와 같이 에러 메시지가 나타나며 진행되지 않는 경우가 있습니다.

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:112:11)
    at Object.join (path.js:375:7)
    at noopServiceWorkerMiddleware (C:\MyProject\mysite\client\node_modules\react-dev-utils\noopServiceWorkerMiddleware.js:14:26)
    at Layer.handle [as handle_request] (C:\MyProject\mysite\client\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:317:13)
    at C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:335:12)
    at next (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:275:10)
    at launchEditorMiddleware (C:\MyProject\mysite\client\node_modules\react-dev-utils\errorOverlayMiddleware.js:20:7)
    at Layer.handle [as handle_request] (C:\MyProject\mysite\client\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:317:13)
    at C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:335:12)
    at next (C:\MyProject\mysite\client\node_modules\express\lib\router\index.js:275:10)
    at handleWebpackInternalMiddleware (C:\MyProject\mysite\client\node_modules\react-dev-utils\evalSourceMapMiddleware.js:42:7)
    at Layer.handle [as handle_request] (C:\MyProject\mysite\client\node_modules\express\lib\router\layer.js:95:5)

내용이 길지만 핵심은 가장 윗줄에 있는 에러입니다.

The "path" argument must be of type string. Received type undefined

해결 방법

이 문제를 해결하기 위해서는 react-scripts 패키지의 요구 버전을 수정해야 합니다. 먼저 React 프로젝트package.json 파일을 열어 dependencies를 확인합니다.

"dependencies": {
    ...
    "react-scripts": "3.3.1"
    ...
}

여기서 react-scripts 패키지의 버전을 확인합니다.

path argument must be of type string 이슈는 react-scripts 3.4.0 버전에서 수정되었습니다. 따라서 최소 요구 버전을 3.4.0 이상으로 올려주어야 합니다. 다음과 같이 수정합니다.

   "react-scripts": "^3.4.0"

이제 불필요한 패키지 관련 캐시를 제거하기 위해 node_modules 폴더를 지워주겠습니다. 터미널에서 rm 명령으로 지우거나 직접 파일 탐색기에서 node_modules 폴더를 지웁니다.

다음으로 package-lock.json 파일이 존재한다면 이 또한 지워주도록 합니다.

이후 터미널에서 npm 명령어를 사용하여 패키지를 모두 재설치합니다. 모든 패키지를 삭제했으므로 재설치에 시간이 소요될 수 있습니다.

$ npm install

설치가 모두 완료되었다면 다시 프로젝트를 빌드하거나 react-scripts를 실행하여 문제가 발생하는지 확인해봅니다.

참고자료

JooTC

안녕하세요. 테크놀로지에 관심이 많은 블로거입니다.

View Comments

Recent Posts

Zalgo 텍스트와 이를 방지하는 방법

인터넷 커뮤니티 사이트에서 게시글이나 댓글에 간혹 장난을 목적으로 작성된 특이한 글자를 볼 수 있습니다. 위…

1개월 ago

리눅스 kill, killall 명령어 – 특정 프로세스 종료하기

리눅스 명령어 - kill, killall 리눅스 kill 명령어는 특정 프로세스를 종료해주는 명령어입니다. 백그라운드에서 실행되고 있는…

1개월 ago

JavaScript typeof null이 ‘object’인 이유

JavaScript는 역사가 긴 스크립트 프로그래밍 언어입니다. 세월이 흐르면서 많은 자바스크립트 표준이 만들어졌고, 현재는 많은 문법적…

1개월 ago

Mocha Error: Resolution method is overspecified. 해결 방법

NodeJS 테스트 프레임워크인 Mocha는 비동기 테스트를 지원합니다. 간혹 특정 테스트 스크립트를 작성하고 실행하면 아래와 같이…

1개월 ago

윈도우 11 설치 시 Microsoft 계정 로그인 없이 로컬 계정 만들기

언제부턴가 윈도우 11을 처음 설치할 때 마이크로소프트(Microsoft) 계정 로그인을 강제로 요구하게 되었습니다. 물론 마이크로소프트 계정이…

7개월 ago

에어팟 프로 2 케이스 스피커 소리를 완전히 끄는 방법

애플 에어팟 프로 2 (AirPods Pro 2) 케이스에는 스피커가 내장되어 있습니다. 그런데 간혹 아무 것도…

9개월 ago