인프런 커뮤니티 질문&답변
back 디렉토리에서 npm install시 node-gyp 에러가 발생합니다.
작성
·
4.4K
·
수정됨
2
결론: 꼼꼼히 질문하려고 글을 작성하다가 문제를 해결했습니다. 하지만 질문이 있어서 마저 남깁니다 :)
운영체제: macOS(Ventura 13.0.1)
Node.js 버전(
node -v): v16.16.0수강중인 강좌: '1강 sleact 강좌 소개 및 기본 세팅'
진행상황: git clone이후, back 디렉토리로 이동했습니다.
에러발생:
npm install시node-gyp에러발생합니다.에러내용
npm ERR! code 1 npm ERR! path /Users/jakinkim/Desktop/study/sleact/back/node_modules/bcrypt npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.0.0 npm ERR! gyp info using node@16.16.0 | darwin | arm64 npm ERR! gyp info find Python using Python version 3.9.6 found at "/Library/Developer/CommandLineTools/usr/bin/python3" npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', npm ERR! gyp info spawn args 'binding.gyp', npm ERR! gyp info spawn args '-f', npm ERR! gyp info spawn args 'make', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/jakinkim/Desktop/study/sleact/back/node_modules/bcrypt/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/jakinkim/Library/Caches/node-gyp/16.16.0/include/node/common.gypi', npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/jakinkim/Library/Caches/node-gyp/16.16.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/jakinkim/Library/Caches/node-gyp/16.16.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/jakinkim/Desktop/study/sleact/back/node_modules/bcrypt', npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! gyp info spawn args '--depth=.', npm ERR! gyp info spawn args '--no-parallel', npm ERR! gyp info spawn args '--generator-output', npm ERR! gyp info spawn args 'build', npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:261:16) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 22.1.0 npm ERR! gyp ERR! command "/usr/local/bin/node" "/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /Users/jakinkim/Desktop/study/sleact/back/node_modules/bcrypt npm ERR! gyp ERR! node -v v16.16.0 npm ERR! gyp ERR! node-gyp -v v9.0.0 npm ERR! gyp ERR! not ok npm ERR! A complete log of this run can be found in: npm ERR! /Users/jakinkim/.npm/_logs/2022-12-12T13_05_39_462Z-debug-0.log시도해본 내용
// node-gyp 설치 npm install -g node-gyp // 설치된 node-gyp 경로찾기 npm root -g node-gyp // 위에서 찾은 경로로 셋팅 npm config set node_gyp /opt/homebrew/lib/node_modules // python 의존성 구성 npm config set python /path/to/executable/python // 프로젝트 build 파일 생성 node-gyp configure // 기존에 설치된 node_modules 및 package-lock.json 삭제 rm -rf node_modules rm package-lock.json // npm update 및 npm install npm update npm install질문
1) 여러 명령들을 실행해봤지만 정확하게 어떤 명령 덕분에 해결이 됐는지 이해가 안됩니다.
2)
npm configure을 해서 back 디렉토리에 build 파일이 생성된 것인지, npm install을 해서 build 파일이 생성된 것인지 애매합니다.(제가 생각하는)에러발생 원인: macOS에서 window등 다른 환경의 git파일을 clone할 때 문제가 발생하는 것 같습니다. 그리고 업데이트 문제인 것 같기도 합니다.
찾아본 내용
node-gyp- Node.js native addon build tool(https://www.npmjs.com/package/node-gyp)Installation notes for macOS Catalina (v10.15)(https://github.com/nodejs/node-gyp/blob/HEAD/macOS_Catalina.md)
npm ERR! code 1 - when npm install #2682(https://github.com/nodejs/node-gyp/issues/2682)
npm install with error:
gypfailed with exit code: 1(https://velog.io/@minho100227/npm-install-with-error-gyp-failed-with-exit-code-1)Writing Native Node.js Modules(https://blog.risingstack.com/writing-native-node-js-modules/)
C++ addons(https://nodejs.org/api/addons.html)





네, 답변 감사합니다.