npm install 错误:“找不到 v120 的构建工具(平台工具集 = 'v120')" [英] npm install error: "The build tools for v120 (Platform Toolset = 'v120') cannot be found"
问题描述
在运行需要 node-gyp 重建的 npm install
时,抛出以下构建错误:
While running an npm install
that required a node-gyp rebuild, the following build error was thrown:
MSB8020:v120 的构建工具(平台工具集 = 'v120')不能被发现.要使用 v120 构建工具进行构建,请安装 v120构建工具.或者,您可以升级到当前的 Visual通过选择 Project 菜单或右键单击 Studio 工具解决方案,然后选择重新定位解决方案"
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"
系统信息
- Windows 10 (x64)
- Visual Studio 2015
- 节点 v0.12.7
- npm v2.11.3
- node-gyp v2.0.1
- 在 VS2015 安装过程中,选择自定义".或者,如果您已经安装了 VS2015,请转到 Windows 的卸载或更改程序"> 从列表中选择 VS2015 > 点击更改"> 点击修改"
- 选中Programming Languages">Visual C++"下的Common Tools for Visual C++ 2015"选项
- 完成 VS2015 安装
- 在 VC++ 安装过程中,选择自定义"
- 检查Windows 8.1 SDK"和Windows 10 SDK"选项
- 完成 VC++ 安装
- 打开 PowerShell
- 使用 msvs_version 参数:
npm install --msvs_version=2015
推荐答案
tl;dr
使用 msvs_version 参数:npm install --msvs_version=2015
如果 msvs_version 参数不起作用,可能是因为您没有安装 Visual C++ 2015 构建环境.
If the msvs_version param doesn't work, it's probably because you don't have a Visual C++ 2015 build environment installed.
选项 2:Visual C++ 构建工具 2015
作为 VS2015 的替代方案,您可以安装 Microsoft 发布的 Visual C++ Build Tools 2015:
使用 msvs_version
现在已经安装了 Visual C++ 2015 构建环境,您可以通过 msvs_version 参数告诉 npm 使用它:
Use msvs_version
Now that a Visual C++ 2015 build environment has been installed, you can tell npm to use it via the msvs_version param:
配置选项(非必需)
或者,您可以将 npm 配置为始终包含 msvs_version 参数,方法是将其添加到您的 npmrc 或 package.json 中,而不是在命令提示符处指定 msvs_version:
Config Options (not required)
Optionally, instead of specifying the msvs_version at the command prompt, you can configure npm to always include the msvs_version param by adding it to your npmrc or package.json:
npmrc
打开 PowerShell 并运行 npm config set msvs_version 2015
,这会将这个参数添加到您的用户 npmrc 文件中.从今以后,每次你运行 npm install
时,作为这个用户,msvs_version=2015
参数将自动被包含
Open PowerShell and run npm config set msvs_version 2015
, which will add this param to your user npmrc file. Henceforth, every time you run npm install
, as this user, the msvs_version=2015
param will automatically be included
如果您计划使用不同的 Windows 帐户登录,并且希望此设置应用于计算机上的所有帐户,则可以选择包含全局标志 npm config set msvs_version 2015 --global
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 文件以包含:
Modify your project's package.json file to include:
"config": {
"msvs_version": 2015
}
从此以后,每次运行 npm install
,对于这个项目,msvs_version=2015
参数将自动包含
Henceforth, every time you run npm install
, for this project, the msvs_version=2015
param will automatically be included
文章修订
- 在受到 Chuck 对 v120 工具集的评论启发的进一步调查后修改了步骤(感谢 @ChuckWalbourn)
- 添加配置选项
- 添加了 VC++ Build Tools 选项
- 更新了正式发布的 VC++ Build Tools 链接
这篇关于npm install 错误:“找不到 v120 的构建工具(平台工具集 = 'v120')"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!