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

无法安装npm包:VS Code贡献时npm install触发node-gyp构建错误

解决VS Code源码npm install时node-gyp/MSBuild编译失败问题

错误信息

npm error gyp ERR! build error
npm error gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
npm error gyp ERR! stack at ChildProcess.<anonymous> (C:\Users\umarm\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:216:23)
npm error gyp ERR! stack at ChildProcess.emit (node:events:524:28)
npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm error gyp ERR! System Windows_NT 10.0.22635
npm error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\umarm\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm error gyp ERR! cwd C:\Users\umarm\OneDrive\code\nodeJS\vscode\node_modules\@vscode\windows-registry
npm error gyp ERR! node -v v22.13.0
npm error gyp ERR! node-gyp -v v11.0.0
npm error gyp ERR! not ok

解决步骤

  • 检查Visual Studio工作负载:打开Visual Studio Installer,确保安装了「桌面开发使用C++」工作负载,同时勾选MSBuild工具和对应系统版本(10.0.22635)的Windows SDK。node-gyp编译原生模块依赖这些组件。
  • 指定node-gyp使用的VS版本:以管理员身份打开命令提示符,执行npm config set msvs_version 2022,强制node-gyp调用VS2022的MSBuild工具。
  • 迁移项目路径:将VS Code源码从OneDrive目录移动到本地非同步目录(比如C:\code\vscode),OneDrive的权限管控或路径特殊字符可能导致编译失败。
  • 清理重装:删除项目根目录的node_modules文件夹和package-lock.json文件,执行npm cache clean --force清理缓存,再重新运行npm install。
  • 核对Node.js版本:查看VS Code源码根目录的CONTRIBUTING.md文档,确认官方推荐的Node.js版本,当前使用的v22.13.0可能过高,建议降级到指定版本(如v20.x系列)后重试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 20:12:09