node-gyp 配置得到“gyp ERR!find VS”

Posted

技术标签:

【中文标题】node-gyp 配置得到“gyp ERR!find VS”【英文标题】:node-gyp configure got "gyp ERR! find VS" 【发布时间】:2019-12-23 18:25:58 【问题描述】:

我正在尝试开始介绍 node c/c++ 附加组件。 node-gyp 命令出错

我已经安装了vs2019,我的命令是

node-gyp configure --msvs_version=2019

详细输出是

gyp info it worked if it ends with ok
gyp info using node-gyp@5.0.3
gyp info using node@10.16.0 | win32 | x64
gyp info find Python using Python version 2.7.15 found at "C:\Users\seact\.windows-build-tools\python27\python.exe"
gyp ERR! find VS 
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2019
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - found in "C:\Program Files (x86)\Microsoft Visual Studio 14.0"
gyp ERR! find VS - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at findVisualStudio2013 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:74:16)
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:344:14)       
gyp ERR! stack     at findVisualStudio2015 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:70:14)
gyp ERR! stack     at regSearchKeys (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:377:20)
gyp ERR! stack     at regGetValue (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\util.js:54:7)
gyp ERR! stack     at D:\Program Files\node-win-x64\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:301:5)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "D:\\Program Files\\node-win-x64\\node.exe" "D:\\Program Files\\node-win-x64\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--msvs_version=2019"
gyp ERR! cwd D:\Projects\learn_node_ext
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok

【问题讨论】:

【参考方案1】:

这是因为没有安装 C++ 构建工具。可以通过在 Visual Studio 安装程序中安装VS 2019 C++ x64/x86 build tools 来解决:

【讨论】:

【参考方案2】:

打开您的 Visual Studio,然后在“搜索框”中搜索 VS 2019 C++ x64/x86 build tools 并安装,然后搜索 Desktop development with C++ 安装它。希望这会有所帮助。

【讨论】:

这对我有用。此外,“VS 2019 C++ x64/86 构建工具”有多个版本。我选择了最高的版本号。【参考方案3】:
    Download Visual Studio Community Edition 运行可执行文件 选择以下选项。

它应该可以解决问题。

【讨论】:

只需选择Desktop development with C++ 即可。【参考方案4】:

您的 powershell 可能在受限模式下运行。 看到这个帖子:how to change PowerShell mode to fulllanguage mode from constrained mode?

【讨论】:

【参考方案5】:

您不必安装 Visual Studio,只需安装 windows 构建工具:

    以管理员身份运行 CMD 运行npm install --g --production windows-build-tools

这应该可以解决这个问题。

【讨论】:

2021 和 npm install --g --production windows-build-tools 安装 python 2.7?跟我开玩笑? :// 这不再有效。 Windows 的官方 node.js 安装程序(节点 16)现在可以选择安装构建工具(python 和 Visual Studio),这也在 repo 的顶部进行了描述:github.com/felixrieseberg/windows-build-tools【参考方案6】:

如果您使用的是 Chocolatey,请安装以下内容:

choco install visualstudio2019buildtools visualstudio2019-workload-vctools

【讨论】:

【参考方案7】:

即使我的 PATH 上有 python,我也必须为 npm 设置 python 路径。

npm config set python /path/to/executable/python

然后再试npm install

【讨论】:

【参考方案8】:

我的朋友创建了项目,她的node/npm 版本与我的不兼容。 所以我尝试只升级我的 npm 版本。问题解决了。

但某些依赖项不起作用。所以我更新了节点版本,以及 npm 版本,将更新。它解决了几乎所有的问题和错误。

您应该找到正确兼容的 node 和 npm 版本。 Here you can find the node version and compatible npm version.

Make sure to check your npm version and node versions are compatible.

【讨论】:

【参考方案9】:

如果有人在完成上述所有步骤后仍然出现 Visual Studio 安装所需的错误。我在尝试运行电子应用程序时遇到了这个问题。我的问题的解决方案是在完成上述所有步骤后将 Visual Studio 添加到环境变量中。

要设置路径,在 cmd 上运行以下命令(如果可能,请以管理员身份):

setx VCTargetsPath “C:\Program Files (x86)\MSBuild\15.0”

注意:我的视觉工作室的路径如上。您可能需要根据您的安装进行更改。

我使用的软件版本如下: 节点:14.17.0 操作系统:windows10 64位 Python:2.7.15(默认安装node js) Visual Studio:社区版 2019

要检查的其他一些事情是确保 python 版本,msvs_version 在 npm 配置中设置为正确的版本。

【讨论】:

【参考方案10】:

不要运行'npm install',而是直接在文件夹中运行'npm update'。这解决了我的问题。

【讨论】:

【参考方案11】:

下载最新的 Visual Studio 构建工具

https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

并在“Program Files (x86)\Microsoft Visual Studio\2017\BuildTools”目录中运行以下命令

npm install --g --production windows-build-tools

在当前目录下安装node-gyp

npm install node-gyp

在 Windows 10 上为我工作

更多信息,请访问official node-gyp安装指南

【讨论】:

【参考方案12】:

在我的电脑上使用下一个命令

npm install --g --production windows-build-tools
npm install node-gyp
npm audit fix
npm install node-phpass

【讨论】:

【参考方案13】:

应该是windows-build-tools的npm包bug。

第 1 步:确保已安装 Visual Studio Code

第2步:在窗口搜索栏下搜索%temp%(复制%temp%然后按windows按钮+Ctrl V)

第 3 步:创建“dd_client_.log.txt”并输入“关闭安装程序”。返回码:3010。'

现在你应该可以用npm install --global windows-build-tools完成整个过程

【讨论】:

以上是关于node-gyp 配置得到“gyp ERR!find VS”的主要内容,如果未能解决你的问题,请参考以下文章

尝试配置或重建 node-gyp 时,出现错误:mac osx mavericks

如何让 node-gyp 在 Windows 7 平台上工作

node-gyp 构建错误窗口 x64

node-gyp的使用

node-gyp 中应用gcov来测试代码覆盖率

构建时的 node-gyp 链接库依赖项