생계유지형 개발자/Stack Over Flow 한국판

[Node] npm 패키지 설치 시 import gyp 에러

이 가을 2024. 4. 30. 12:25

컴퓨터를 교체하고 기존에 개발하던 Vue 프로젝트 실행하고자 npm install 명령어 입력하였으나 아래와 같은 오류가 발생했다.

node-gyp 라는 모듈 안에서 발생한 것 같았다.

node@12 사용할 때는 문제가 없었던 것 같은데.. 16으로 업그레이드하고서 문제가 생긴 것 같다.

node 12 또는 14 버전을 설치해보려고 했지만 옛 버전이라 brew를 통해서는 설치가 안 되는 것 같았다.

----

내 컴퓨터에 설치된 모듈버전은 다음과 같다.

node -v 16.20.2

npm -v 8.19.4

 

# 오류

npm ERR! code 1 npm ERR! path /Users/user/Documents/GitHub/nesp/nesp-v2/nesp-web-vue/node_modules/deasync npm ERR! command failed npm ERR! command sh -c -- node ./build.js npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.1.0 npm ERR! gyp info using node@16.20.2 | darwin | arm64 npm ERR! gyp info find Python using Python version 3.12.3 found at "/opt/homebrew/opt/python@3.12/bin/python3.12" npm ERR! gyp info spawn /opt/homebrew/opt/python@3.12/bin/python3.12 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/opt/homebrew/Cellar/node@16/16.20.2_1/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/user/Documents/GitHub/nesp/nesp-v2/nesp-web-vue/node_modules/deasync/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/user/Library/Caches/node-gyp/16.20.2/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/user/Library/Caches/node-gyp/16.20.2', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/user/Library/Caches/node-gyp/16.20.2/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/user/Documents/GitHub/nesp/nesp-v2/nesp-web-vue/node_modules/deasync', 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! Traceback (most recent call last): npm ERR! File "/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module> npm ERR! import gyp # noqa: E402 npm ERR! ^^^^^^^^^^ npm ERR! File "/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module> npm ERR! import gyp.input npm ERR! File "/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module> npm ERR! from distutils.version import StrictVersion npm ERR! ModuleNotFoundError: No module named 'distutils' 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/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:284:16) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12) npm ERR! gyp ERR! System Darwin 23.4.0 npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@16/16.20.2_1/bin/node" "/opt/homebrew/Cellar/node@16/16.20.2_1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /Users/user/Documents/GitHub/nesp/nesp-v2/nesp-web-vue/node_modules/deasync npm ERR! gyp ERR! node -v v16.20.2 npm ERR! gyp ERR! node-gyp -v v9.1.0 npm ERR! gyp ERR! not ok npm ERR! Build failed

 

# 원인

위 에러메세지에서 주목할 부분은 붉은색으로 표기된 부분이다.

해당 모듈이 없어서 문제가 되는 것 같은데 처음 보는 모듈이다.

 

# 해결

터미널에서 아래 세 명렁어 실행하여 설치하니까 오류없이 npm isntall 성공했다.

npm i -g node-gyp
brew install python@3.12
brew install python-setuptools

 

 

※ 참고

https://stackoverflow.com/questions/69919970/no-module-named-distutils-but-distutils-installed

 

no module named distutils....but distutils installed?

I was wanting to upgrade my python version (to 3.10 in this case) so after installing python3.10 I proceeded to try adding some modules I use e.g. opencv , which ran into: jeremy@jeremy-Blade:~$ py...

stackoverflow.com

https://stackoverflow.com/questions/77549389/i-get-import-gyp-error-when-try-to-install-package-for-electron

 

I get import gyp error when try to install package for electron

I tried to install on Windows the demo from this repository: https://github.com/Seo-Rii/electron-acrylic-window git clone https://github.com/Seo-Rii/electron-acrylic-window.git cd electron-acrylic-...

stackoverflow.com