所有Visual Studio安装程序都会崩溃,并且视觉生成工具也无法使用

如果nodejs(特别是node-gyp)不依赖Visual Studio,那么我根本不会使用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只是在其他目录中。这是它应该位于的目录,它不存在。

我该如何解决?

susanlixinyu 回答:所有Visual Studio安装程序都会崩溃,并且视觉生成工具也无法使用

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

好吧,之后事实证明这很容易。这是您需要做的:

  • npm config set 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. CMD
      • 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 \,所以请不要更改它。

本文链接:https://www.f2er.com/3060173.html

大家都在问