npm install error: "The build tools for v120 (Platform Toolset = 'v120') cannot be found"

npm install error: "The build tools for v120 (Platform Toolset = 'v120') cannot be found"

虽然 运行 一个 npm install 需要 node-gyp 重建,但引发了以下构建错误:

MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution"

系统信息

tl;博士

使用 msvs_version 参数:npm install --msvs_version=2015

如果 msvs_version 参数不起作用怎么办?

如果 msvs_version 参数不起作用,可能是因为您没有安装 Visual C++ 2015 构建环境。

安装 Visual C++ 构建环境

选项 1:Visual Studio2015

  1. 安装VS2015时,select"Custom"。或者,如果您已经安装了 VS2015,请从列表转到 Windows' "Uninstall or change a program" > select VS2015 > 单击 "Change" > 单击 "Modify"
  2. 选中 "Common Tools for Visual C++ 2015" 选项,在 "Programming Languages" > "Visual C++"
  3. 完成VS2015安装

选项 2:Visual C++ 构建工具 2015

作为VS2015的替代品,可以安装微软发布的Visual C++ Build Tools 2015

  1. 在 VC++ 安装过程中,select "Custom"
  2. 检查 "Windows 8.1 SDK" 和 "Windows 10 SDK" 选项
  3. 完成 VC++ 安装

使用msvs_version

现在已经安装了 Visual C++ 2015 构建环境,您可以通过 msvs_version 参数告诉 npm 使用它:

  1. 打开 PowerShell
  2. 使用 msvs_version 参数:npm install --msvs_version=2015

配置选项(非必需)

可选地,而不是在命令提示符下指定 msvs_version,您可以将 npm 配置为始终包含 msvs_version 参数,方法是将其添加到您的 npmrc 或 package.json:

npmrc

打开 PowerShell 和 运行 npm config set msvs_version 2015,这会将此参数添加到您的用户 npmrc 文件中。此后,每次您 运行 npm install 作为该用户时, msvs_version=2015 参数将自动包含

optionally, you can include the global flag npm config set msvs_version 2015 --global if you plan on logging in with different Windows accounts, and you want this setting to apply to all accounts on the machine

package.json

修改项目的 package.json 文件以包含:

"config": {
  "msvs_version": 2015
}

以后,每次你运行npm install,对于这个项目,msvs_version=2015参数将自动包含


文章修订

  1. 根据 Chuck 关于 v120 工具集的评论(感谢@ChuckWalbourn)进一步调查后修改了步骤
  2. 添加了配置选项
  3. 添加了 VC++ 构建工具选项
  4. 已更新 VC++ 构建工具 link 正式发布

我想对 2Toad 的回答添加评论,但 Whosebug 不允许。 您可以使用此命令全局设置 msvs_version:

npm config set msvs_version 2015 --global

这样就省去了将它放在每个项目配置对象中的麻烦。

将版本设置为 2015 对我没有帮助。尝试将其设置为 2013:

npm 配置集 msvs_version 2013

npm 配置集 msvs_version 2015

我将分享这个答案,因为 none 的其他修复解决了我的问题。我遇到了同样的错误,但设置了 msvs 参数:

npm install --msvs_version=2015

没有解决问题。无论我做什么,我都可以看到它在错误的地方寻找工具集。

长话短说,我了解到 MSBuild 现在与 Visual Studio 一起打包,不再与 .NET 一起打包。果然我在 PATH 变量中有这个条目:

C:\Windows\Microsoft.NET\Framework\v4.0.30319;

因此调用了错误的(旧)版本的 MSBuild。我删除了这个条目并添加了以下与 VS2015 相关的路径:

C:\Program Files (x86)\MSBuild.0\Bin\

问题已解决。

我已经花了 2 天时间安装所有 VS 版本...

npm install oracledb --msvs_version=2015

Return 很多错误:

[..]node-gyp.9.1\include\node\v8.h(18): fatal error C1083[..]

使用

npm install oracledb --msvs_version=2013

Return很多警告,编译后不能正常工作。

[..]warning C4995: 'v8::Value::ToUint32'[..]

这是我使用 npm 模块最糟糕的经历。真是浪费时间:/