npm node gyp失败怎么办

藏色散人
藏色散人原创
2022-12-29 14:42:011595浏览

npm node gyp失败是因为“node-gyp.js”跟“Node.js”版本不匹配,其解决办法:1、通过“npm cache clean -f”清除node缓存;2、通过“npm install -g n”安装n模块;3、通过“n v12.21.0”命令安装“node v12.21.0”版本即可。

本教程操作环境:Windows10系统、node v12.21.0版、Dell G3电脑。

npm node gyp失败怎么办?

npm install报node-gyp相关错误

我在构建一个vue项目时,报了node-gyp构建相关错误,错误信息如下

1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/xingxin/code_sxf2/nft-server/nft-ui/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 20.4.0
gyp ERR! command "/usr/local/bin/node" "/Users/xingxin/code_sxf2/nft-server/nft-ui/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/xingxin/code_sxf2/nft-server/nft-ui/node_modules/node-sass
gyp ERR! node -v v16.15.1

经过各种尝试才发现

原因是node-gyp.js跟我的Node.js版本不匹配,我的Node版本太高了

经过尝试发现Node降级到 v12.21.0版本后,构建成功。

降级操作相关命令:

# 查看当前node版本
node –v
# 清除node缓存
npm cache clean -f
# 安装n模块
npm install -g n
# 安装v12.21.0版本
n v12.21.0
# 查看当前node版本
node –v

推荐学习:《node.js视频教程

以上就是npm node gyp失败怎么办的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。