You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装grpc-tools时遇node-gyp编译错误,寻求解决方法

安装grpc-tools遇到的node-pre-gyp与MSBuild编译错误问题

问题现象

安装grpc-tools时出现以下核心错误:

  • node-pre-gyp无法找到适配node@16.17.0的grpc@1.24.2预编译二进制文件(请求返回404)
  • 自动切换为node-gyp源码编译,最终MSBuild执行失败,退出码为1

完整错误日志:

npm ERR!   win_delay_load_hook.cc npm ERR!   z.vcxproj -> F:\NodeJS Projects\Noosa\npg\node_modules\grpc\build\Release\\libz.lib
npm ERR! Failed to execute 'F:\Node js\node.exe C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --library=static_library --module=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown\grpc_node.node
--module_name=grpc_node --module_path=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1) npm ERR! node-pre-gyp info it worked if it ends with ok npm ERR! node-pre-gyp info using node-pre-gyp@0.14.0 npm ERR! node-pre-gyp info using node@16.17.0 | win32 | x64 npm ERR! node-pre-gyp WARN Using request for node-pre-gyp https download npm ERR! node-pre-gyp info check checked for "F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown\grpc_node.node" (not found) npm ERR! node-pre-gyp http GET https://node-precompiled-binaries.grpc.io/grpc/v1.24.2/node-v93-win32-x64-unknown.tar.gz
npm ERR! node-pre-gyp http 404 https://node-precompiled-binaries.grpc.io/grpc/v1.24.2/node-v93-win32-x64-unknown.tar.gz
npm ERR! node-pre-gyp WARN Tried to download(404): https://node-precompiled-binaries.grpc.io/grpc/v1.24.2/node-v93-win32-x64-unknown.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not found for grpc@1.24.2 and node@16.17.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp)  npm ERR! node-pre-gyp http 404 status code downloading tarball https://node-precompiled-binaries.grpc.io/grpc/v1.24.2/node-v93-win32-x64-unknown.tar.gz
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.17.0 | win32 | x64 npm ERR! gyp info ok 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.17.0 | win32 | x64 npm ERR! gyp info find Python using Python version 3.10.6 found at "C:\Users\Lidor German\AppData\Local\Programs\Python\Python310\python.exe" npm ERR! gyp info find VS using VS2017 (15.9.28307.1500) found at: npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" npm ERR! gyp info find VS run with --verbose for detailed information npm ERR! gyp info spawn C:\Users\Lidor German\AppData\Local\Programs\Python\Python310\python.exe npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args   'C:\Users\Lidor German\AppData\Roaming\npm\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   'msvs', npm ERR! gyp info spawn args   '-I', npm ERR! gyp info spawn args   'F:\NodeJS Projects\Noosa\npg\node_modules\grpc\build\config.gypi', npm ERR! gyp info spawn args   '-I', npm ERR! gyp info spawn args 'C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\addon.gypi', npm ERR! gyp info spawn args   '-I', npm ERR! gyp info spawn args 'C:\Users\Lidor German\AppData\Local\node-gyp\Cache\16.17.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=C:\Users\Lidor German\AppData\Local\node-gyp\Cache\16.17.0', npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp', npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\Users\\Lidor German\\AppData\\Local\\node-gyp\\Cache\\16.17.0\\<(target_arch)\\node.lib', npm ERR! gyp info spawn args   '-Dmodule_root_dir=F:\NodeJS Projects\Noosa\npg\node_modules\grpc', 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 'F:\NodeJS Projects\Noosa\npg\node_modules\grpc\build', npm ERR! gyp info spawn args   '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! gyp info ok 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.17.0 | win32 | x64 npm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args   'build/binding.sln', npm ERR! gyp info spawn args   '/clp:Verbosity=minimal', npm ERR! gyp info spawn args   '/nologo', npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64' npm ERR! gyp info spawn args ] npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: <code>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe</code> failed with exit code: 1 npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:201:23) 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:291:12) npm ERR! gyp ERR! System Windows_NT 10.0.19044 npm ERR! gyp ERR! command "F:\Node js\node.exe" "C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "build" "--fallback-to-build" "--library=static_library" "--module=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown\grpc_node.node" "--module_name=grpc_node" "--module_path=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93" npm ERR! gyp ERR! cwd F:\NodeJS Projects\Noosa\npg\node_modules\grpc npm ERR! gyp ERR! node -v v16.17.0 npm ERR! gyp ERR! node-gyp -v v9.1.0 npm ERR! gyp ERR! not ok npm ERR! node-pre-gyp ERR! build error npm ERR! node-pre-gyp ERR! stack Error: Failed to execute 'F:\Node js\node.exe C:\Users\Lidor German\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --library=static_library --module=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown\grpc_node.node --module_name=grpc_node --module_path=F:\NodeJS Projects\Noosa\npg\node_modules\grpc\src\node\extension_binary\node-v93-win32-x64-unknown --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1) npm ERR! node-pre-gyp ERR! stack     at ChildProcess. (F:\NodeJS Projects\Noosa\npg\node_modules\grpc\node_modules\node-pre-gyp\lib\util\compile.js:83:29) npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:513:28) npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1093:16) npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) npm ERR! node-pre-gyp ERR! System Windows_NT 10.0.19044 npm ERR! node-pre-gyp ERR! command "F:\Node js\node.exe" "F:\NodeJS Projects\Noosa\npg\node_modules\grpc\node_modules\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build" "--library=static_library" npm ERR! node-pre-gyp ERR! cwd F:\NodeJS Projects\Noosa\npg\node_modules\grpc npm ERR! node-pre-gyp ERR! node -v v16.17.0 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v0.14.0 npm ERR! node-pre-gyp ERR! not ok   npm ERR! A complete log of this run can be found in: npm ERR!     C:\Users\Lidor German\AppData\Local\npm-cache_logs\2022-09-05T08_30_41_064Z-debug-0.log

解决方案

方案1:升级grpc版本到支持Node.js 16的版本

grpc@1.24.2属于旧版本,不兼容Node.js 16(node-v93 ABI)。直接安装最新兼容版本:

npm install grpc@latest --save

也可以指定明确支持Node.js 16的版本,比如grpc@1.27.x及以上。

方案2:降级Node.js到grpc@1.24.2支持的版本

grpc@1.24.2最高支持Node.js 12(node-v72 ABI),可通过nvm切换版本:

# 安装nvm(未安装时执行)
nvm install 12.22.12
nvm use 12.22.12
# 重新安装grpc-tools
npm install grpc-tools

方案3:修复源码编译环境问题

若必须保留当前Node.js和grpc版本,需解决MSBuild编译失败问题:

  • 确认Visual Studio 2017 Build Tools已安装C++开发工具和匹配Windows系统的SDK
  • 以管理员身份打开命令提示符,重新执行安装命令
  • 清理npm缓存后重试:
    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    

内容的提问来源于stack exchange,提问作者D3mocracy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 11:31:06