node-gyp在windows安装出错解决方案

错误1:

error Error: getaddrinfo ENOTFOUND registry.nlark.com at GetAddrInfoReqWrap.

解决1:

修改yarn.lock文件里registry.nlark.com  改为 registry.npmmirror.com


错误2:

gyp verb check python checking for Python executable "python2" in the PATH g

解决2:

这个错误信息是由node-gyp在尝试找到Python 2.x版本时产生的,因为node-gyp需要Python 2.x来构建一些本地的C++扩展。

首先需要安装Python 2.x版本,配置环境变量。

接着执行:

mklink /H D:\Python27\python2.exe D:\Python27\python.exe

将python映射为python2


错误3:

gyp ERR! stack Error: spawn D:\Microsoft Visual Studio\MSBuild\15.0\Bin\MSBuild.exe

解决3:

重新设置MSBuild编译器版本和路径

比如我的:

npm config set msbuild_path “D:\Microsoft Visual Studio\MSBuild\Current\Bin\MSBuild.exe”

错误4:

gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack Error: spawn D:\Microsoft ENOENT
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:19)
gyp ERR! stack     at onErrorNT (internal/child_process.js:472:16)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "D:\\Node.js\\node.exe" "D:\\hytCode\\20240505\\console\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\hytCode\20240505\console\node_modules\node-sass
gyp ERR! node-gyp -v v3.8.0
gyp ERR! This is a bug in `node-gyp`.

即使改了编译器版本和路径,它还是找不到指定的路径或文件。

具体来说,错误信息显示 spawn D:\Microsoft ENOENT,这意味着系统尝试在 D:\Microsoft 目录中找到 MSBuild,但没有成功。

解决4:

手动指定 msbuild_path: 如果设置环境变量后仍然有问题,你可以在构建命令中手动指定 msbuild_path

在你的项目目录中创建或编辑 .npmrc 文件

你可以通过这样找到:按住 win+E输入%USERPROFILE%

可以找到.npmrc文件

添加如下内容

可以看到文件内容:

sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
msbuild_path=D:\Microsoft

可以看到msbuild_path的路径为报错的路径

将msbuild_path改为:

msbuild_path=D:\Microsoft Visual Studio\MSBuild\Current\Bin\MSBuild.exe

点击保存,重新编译即可。

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值