如何设置 VCINSTALLDIR

der*_*ner 8 visual-studio npm

我正在尝试使用安装节点调试npm i ndb --global,但出现此错误:

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 - not found
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 ***********************
Run Code Online (Sandbox Code Playgroud)

我有 Visual Studio 2019 Community Edition,具有桌面开发功能,并安装了 C++ 工作负载。早些时候我已经像这样设置了 msvs_version :npm config set msvs_version=2019

那么,问题是,如何设置 VCINSTALLDIR 变量?

Mik*_*keF 0

尝试在 Visualo Studio 中打开命令提示符。运行SET VSIN以获取变量的当前值。就我而言:

VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\

使用 GUI 或命令行设置变量。请注意,由于路径中存在空格,您必须使用“标记。然后,因为它以斜杠结尾,您需要转义最后一个斜杠,否则它将选择最后一个”作为变量的一部分。

`SETX VSINSTALLDIR C:\Program Files\Microsoft Visual Studio\2022\Community\"

现在重新启动您正在运行的终端npm ...,您应该看到变量已设置。