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

如何解决npm install报错“npm ERR! code 1”(依赖编译失败)

问题描述

尝试安装StickyImageEffect项目时,执行npm install出现以下报错:

npm ERR! code 1
npm ERR! path C:\xampp\htdocs\sss\node_modules\deasync
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node ./build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@18.13.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.11.1 found at "C:\Users\Admin\AppData\Local\Programs\Python\Python311\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community"npm ERR! gyp ERR! find VS checking VS2019 (16.11.33214.272) found at:
npm ERR! gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"
npm ERR! gyp ERR! find VS - missing any VC++ toolset
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:427:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
npm ERR! gyp ERR! System Windows_NT 10.0.19045
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\xampp\htdocs\sss\node_modules\deasync
npm ERR! gyp ERR! node -v v18.13.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
npm ERR! Build failed

已尝试重新安装Node.js,但问题未解决,求解决方法。

解决方案

报错核心是node-gyp无法找到可用的Visual Studio C++编译工具集,以下是针对性解决步骤:

1. 安装/修复Visual Studio编译工具

  • 若已安装Visual Studio 2019/2022,打开Visual Studio Installer,选择对应版本点击「修改」。
  • 在工作负载列表中勾选Desktop development with C++,确保包含以下组件:
    • MSVC v142/V143生成工具(对应你VS版本的最新工具集)
    • 匹配系统版本的Windows SDK(如Windows 10 1904x)
    • C++ CMake工具(可选但推荐)
  • 点击「修改」,安装完成后重启电脑。

2. 配置npm指向正确的VS版本

以管理员身份打开命令提示符,执行:

npm config set msvs_version 2022  # 若安装的是VS2019则替换为2019

3. 验证Python版本兼容性

node-gyp对Python 3.11的支持存在兼容性问题,建议切换到Python 3.8-3.10版本:

  • 安装对应版本的Python,勾选「Add Python to PATH」。
  • 执行命令配置npm使用该Python:
npm config set python "C:\路径\到\python.exe"

4. 清理缓存后重新安装

npm cache clean --force
# Windows系统执行以下命令
rmdir /s /q node_modules
del package-lock.json
npm install

替代方案:使用windows-build-tools

若不想安装完整Visual Studio,可通过npm安装轻量编译工具集:

npm install --global windows-build-tools --force

安装完成后重启命令提示符,再执行npm install。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 07:40:24