개발/디버깅

npm install 오류 (Windows10/WSL/Ubuntu/PowerShell)

김알리 2021. 11. 8. 23:32
728x90
반응형

 

 Node.js에 자바를 연결하기 위해 npm i java 를 실행했다. 자바 파일, nvm, node 다 제대로 깔려 있었고, node-gyp과 gyp에서 필요한 파이썬까지도 제대로 깔려 있었는데 이상하게 아래와 같은 오류가 뜨면서 설치가 되지 않았다. 계속 구글링을 하며 오류를 해결하려고 노력해 보았고, 이것 저것 지우고 다시 깔아보았지만 해결이 되지 않았다.

 

> java@0.12.2 install /mnt/c/WINDOWS/system32/node_modules/java
> node-gyp rebuild
(node:3938) UnhandledPromiseRejectionWarning: TypeError [ERR_STREAM_NULL_VALUES]: May not write null values to stream
    at validChunk (_stream_writable.js:279:10)
    at Socket.Writable.write (_stream_writable.js:316:21)
    at /mnt/c/WINDOWS/system32/node_modules/java/findJavaHome.js:6:18
    at /mnt/c/WINDOWS/system32/node_modules/find-java-home/dist/index.js:103:21
    at step (/mnt/c/WINDOWS/system32/node_modules/find-java-home/dist/index.js:46:23)
    at Object.next (/mnt/c/WINDOWS/system32/node_modules/find-java-home/dist/index.js:27:53)
    at fulfilled (/mnt/c/WINDOWS/system32/node_modules/find-java-home/dist/index.js:18:58)
(node:3938) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3938) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
gyp: Call to 'node findJavaHome.js' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/username/.nvm/versions/node/v12.22.7/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Linux 4.4.0-19041-Microsoft
gyp ERR! command "/home/username/.nvm/versions/node/v12.22.7/bin/node" "/home/username/.nvm/versions/node/v12.22.7/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /mnt/c/WINDOWS/system32/node_modules/java
gyp ERR! node -v v12.22.7
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open '/mnt/c/WINDOWS/system32/package.json'
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! java@0.12.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the java@0.12.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/username/.npm/_logs/2021-11-05T02_06_17_404Z-debug.log

 

 

 알고 보니 내가 정말 바보 같은 실수를 한 것이었다. 바로 터미널로 WSL을 사용한 것이다. WSL는 Windows 10부터 리눅스 서버를 지원하는 것인데, 자바와 파이썬 모두 실제로 컴퓨터에 설치할 때는 윈도우용을 깔았다. 리눅스 서버에서 윈도우용 자바와 파이썬을 사용하려고 한 것이다. 그러니 당연히 될 리가... 게다가 리눅스와 윈도우는 파일 시스템 구조 자체가 다르니 아예 파일을 찾지도 못한 것이다. 

 

 

 gyp failed with exit code 1라는 오류는 별 이유 없이도 생기는 것 같긴 한데, (링크 user728650의 답변의 댓글 참고) 구글링 결과 Python이 제대로 설치되지 않는 경우에 뜬다고 한다.

 

 

 

또한, 아래의 에러 메세지를 봐도 계속 null값이 나타나거나 파일 혹은 디렉토리가 없다는 에러를 낸다. 컴퓨터의 입장에서는 아예 파이썬도 없고 자바도 없는데 계속 Node.js와 연결하려고 하는 상황이었던 것이다. 

  • (node:3938) UnhandledPromiseRejectionWarning: TypeError [ERR_STREAM_NULL_VALUES]: May not write null values to stream
  • npm WARN enoent ENOENT: no such file or directory, open '/mnt/c/WINDOWS/system32/package.json'
  • gyp: Call to 'node findJavaHome.js' returned exit status 0 while in binding.gyp. while trying to load binding.gyp

 

 

정말 어처구니 없이 몇 시간을 허비해서 허무하다. 너무 멍청한 실수라 창피하지만, 나만 멍청한 것은 아닐 거야.

728x90
반응형