본문으로 바로가기

npm ERR! Cannot read properties of undefined (reading 'stdin')

category 코딩/node.js 2022. 6. 8. 13:21

 

에러 상황

node express 로 구성한 서버를 구동하려고, 터미널에서 npm start 명령을 실행하였더니 아래 오류 메시지 발생.

 

$ npm start

> default@1.0.0 start
> node app.js

npm ERR! Cannot read properties of undefined (reading 'stdin')

npm ERR! A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2023-06-29T05_59_33_493Z-debug-0.log

 

테스트

npm startpackage.json 파일의 scripts 부분에 명시된 명령을 수행하므로, 해당 명령어를 터미널에서 직접 실행해 본다.

$ node app.js

 

하지만 서버가 바로 종료된다.

express 기반이므로 그럴 수 있다.

 

node ./bin/www

 

정상 실행된다. 그럼 package.json 파일을 수정 후 npm start 명령어로 실행해본다.

 

...(생략)...
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node ./bin/www"
  },
...(생략)...

 

$ npm start

> default@1.0.0 start
> node ./bin/www

npm ERR! Cannot read properties of undefined (reading 'stdin')

npm ERR! A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2023-06-29T08_00_20_419Z-debug-0.log

 

npm start 로는 여전히 실행이 안된다. 

 

해결 방법

아래 순서로 시도해 본다.

 

  1. npm cache clear --force
  2. node_modules 폴더, package.json 파일 삭제
  3. npm install
  4. node.js 삭제 후 재설치
  5. npm 버전 업그레이드 npm install npm -g
  6. npm 버전 다운그레이드 npm install npm@버전 -g

 

3번까지 시도해 보았을 때도 여전히 오류가 발생한다면, 이후는 현재 버전을 기록, 중요 파일은 백업 후 나머지 진행.

그런데 다운그레이드 했다가 돌이킬 수 없는 문제가 발생 했다는 케이스를 보았다.

3번까지 해 보고 안되면 백그라운드 또는 forever 로 실행하는게 좋겠다.