gpt4 book ai didi

c++ - 所有 visual studio 安装程序崩溃,可视化构建工具也无法工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:11 25 4
gpt4 key购买 nike

如果 nodejs 尤其是 node-gyp 不依赖于 Visual Studio,我根本不会乱搞它。我真正想做的就是安装 active-win npm 包,但因为它有一个窗口 API 依赖项,我需要运行 node-gyp,这让我掉进了这个兔子洞。

无论出于何种原因,2015 visual studio 安装程序崩溃了,但我只是使用了 npm install --global --production 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

> iconv@2.3.5 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

> ref-napi@1.4.2 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/date-fns@1.3.11 requires a peer of date-fns@2.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN extract-text-webpack-plugin@3.0.2 requires a peer of webpack@^3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.3.5 (node_modules\iconv):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.3.5 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref-napi@1.4.2 (node_modules\ref-napi):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref-napi@1.4.2 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ active-win@6.0.0
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 配置或注册表中设置它。我试过了。
    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com