node-gyp 错误找不到要使用的任何 Visual Studio 安装

Posted

技术标签:

【中文标题】node-gyp 错误找不到要使用的任何 Visual Studio 安装【英文标题】:node-gyp error Could not find any Visual Studio installation to use 【发布时间】:2022-01-15 19:05:55 【问题描述】:

我遇到的问题是我无法为项目安装软件包,它不断出错:

npm ERR! npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! npm ERR! gyp ERR! find VS
npm ERR! npm ERR! gyp ERR! find VS **************************************************************
npm ERR! npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! npm ERR! gyp ERR! find VS **************************************************************

我试图听从其他人的这些帖子的建议:

How to fix node.js error like "gyp ERR! find VS including the "Desktop development with C++" workload." when I launch Nuxt.js project

还有这个How can I solve error gypgyp ERR!ERR! find VSfind VS msvs_version not set from command line or npm config?

但似乎都没有帮助。

到目前为止我做了什么:

我用Desktop development with C++MSVC v143 - VS 2022 C++ x64/x86 build tools 安装了最新的VS Code(2022 社区)

我已将msvs_version 配置为具有2022 的值,我使用npm config set msvs_version=2022node-gyp configure --msvs_version=2022 做到了这一点

我尝试安装 Windows 构建工具 npm install --global --production windows-build-tools 但它只是说 ...Node.js now incldues build tools for Windows...

我还使用上面列出的第二篇文章中的命令手动构建了 node-gyp node-gyp configure node-gyp configure --msvs_version=2022 node-gyp build 及其所有的绿色和好的

我不知道我还能做什么

【问题讨论】:

【参考方案1】:

经过几个小时的搜索,我发现了问题,这是我的节点版本,我当时是 16.x.x,我安装了节点版本管理器并移至版本 14,它可以工作。

【讨论】:

以上是关于node-gyp 错误找不到要使用的任何 Visual Studio 安装的主要内容,如果未能解决你的问题,请参考以下文章

nodejs/electron-forge/node-gyp:在尝试了我可以在网上找到的所有提示后,找不到任何要使用的 Visual Studio 安装

Node-Gyp 在尝试安装 Brain.js 时返回错误

安装了vs2019 编译node-sass node-gyp 找不到编译器的解决方法

从 jenkins 构建一个 git 项目时,它显示一个错误,例如找不到要构建的任何修订

npm 安装错误:“找不到 v120(平台工具集 = 'v120')的构建工具”

SBT 找不到要运行或编译的测试