c++ - 所有 Visual Studio 安装程序都会崩溃,并且可视化构建工具也无法工作

标签 c++ node.js npm node-gyp

如果nodejs,特别是node-gyp不依赖于它,我根本就不会使用Visual Studio。我真正想做的就是安装 active-win npm 包,但因为它有一个窗口 API 依赖项,所以我需要运行 node-gyp,这让我陷入了这个兔子洞。

无论出于何种原因,2015 Visual Studio 安装程序崩溃了,但我只是使用了 npm install --global --product windows-build-tools。它成功安装了构建工具,但是,这里的问题仍然存在。

这也是一个较小的错误,尽管 msmversion 设置为 2015,node-gyp 仍尝试在/v120/中查找,我通过设置 VCTargetsPath 位置修复了此问题。

这是此时运行 npm i -D active-win 的完整错误:

C:\Users\Henry Hunt\Documents\GitRep\ludite>npm install -D active-win

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cda4aea2a3bb8dffe3fee3f8" rel="noreferrer noopener nofollow">[email protected]</a> install C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\iconv
> node-gyp rebuild


C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\iconv>if not defined npm_config_node_gyp (node "N:\Nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "N:\Nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\iconv\build\iconv.vcxproj(20,3): error MSB4019: The imported p
roject "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.props" was not found. Confirm that
 the path in the <Import> declaration is correct, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (N:\Nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "N:\\Nodejs\\node.exe" "N:\\Nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\iconv
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2c0d7d49fdcd3c2dbf2839c869c80" rel="noreferrer noopener nofollow">[email protected]</a> install C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\ref-napi
> node-gyp rebuild


C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\ref-napi>if not defined npm_config_node_gyp (node "N:\Nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "N:\Nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\ref-napi\node_modules\node-addon-api\src\nothing.vcxproj(20,3)
: error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.pro
ps" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (N:\Nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "N:\\Nodejs\\node.exe" "N:\\Nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Henry Hunt\Documents\GitRep\ludite\node_modules\ref-napi
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN @date-io/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b4b1a4b5fdb6bea390e1fee3fee1e1" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0a0f1a0b4308001d2e5c405f405e" rel="noreferrer noopener nofollow">[email protected]</a> but none is installed. You must install peer dependencies yourself.
npm WARN <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="acc9d4d8decdcfd881d8c9d4d881dbc9cedccdcfc781dcc0d9cbc5c2ec9f829c829e" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of webpack@^3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="563f35393820166478657863" rel="noreferrer noopener nofollow">[email protected]</a> (node_modules\iconv):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed7ddd1d0c8fe8c908d908b" rel="noreferrer noopener nofollow">[email protected]</a> install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75071013581b14051c35445b415b47" rel="noreferrer noopener nofollow">[email protected]</a> (node_modules\ref-napi):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d1f080b40030c1d042d5c4359435f" rel="noreferrer noopener nofollow">[email protected]</a> install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5d4d6c1dcc3d098c2dcdbf5839b859b85" rel="noreferrer noopener nofollow">[email protected]</a>
added 2 packages from 3 contributors, updated 1 package and audited 10413 packages in 6.338s
found 0 vulnerabilities

安装的构建工具版本是2015,其进入\V140\的文件夹实际上是存储配置的位置。缺少的一个文件是 Microsoft.Cpp.Default.props。我找不到任何遇到同样问题的人。有很多人有同样的错误,但在解决他们的问题时,Microsoft.Cpp.Default.props 只是在其他目录中。这是它应该位于的目录,但它不在那里。

如何解决这个问题?

最佳答案

首先,我下载了 Visual Studio 2019,而不是使用 node_build_tools。尽管 Node 构建工具声称已安装实际的 C:/Program Files (x86)/MSBuild,但其中没有 npm 所需的任何文件。在我完全卸载以前的 Visual Studio 安装程序后,2019 年的安装程序运行良好。

嗯,在那之后,事情变得非常简单。您需要执行以下操作:

  • npm 配置集 msvs_version 2019
  • npm config set msbuild_path "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"
  • 然后设置 VCTargetsPath 本地环境变量,不,您不能简单地在 npm config 或注册表中设置它。我试过了。
    1. 命令提示符
      • SET VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\
      • (不要忘记最后一个反斜杠,否则将不起作用)
    2. GitBash 或其他类似 bash 的 shell
      • VCTargetsPath="C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Microsoft\\VC\\v160\\"<

注意:虽然 Visual Studio 会让您选择 Visual Studio IDE 文件夹的安装位置,但这只是 IDE 将文件保存到计算机上的任何路径或驱动器的默认位置,即上面的实际 Microsoft Visual Studio 文件夹始终安装到 C:\Program Files (x86)\Microsoft Visual Studio\,因此不要更改它。

关于c++ - 所有 Visual Studio 安装程序都会崩溃,并且可视化构建工具也无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58969271/

相关文章:

c++ - 在 C++ 中获取/设置日期和时间

c++ - 在C++中使用WinUI的指南

node.js - 无法实现转换流

node.js - 在 node/express 中找不到 View

node.js - Sequelize 模型 - 在 Node 中同步时设置关联

npm - YARN 或 NPM 软件包安装缺少 src 文件夹

javascript - npm 安装在不在 node_modules/中的模块上

node.js - PM2 日志文件的默认位置是什么?

c++ - 基准代码——是否除以迭代次数?

c++ - 整数到 bool 数组