18

While running an npm install that required a node-gyp rebuild, the following build error was thrown:

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"

System Information

  • Windows 10 (x64)
  • Visual Studio 2015
  • node v0.12.7
  • npm v2.11.3
  • node-gyp v2.0.1

5 Answers 5

45

tl;dr

Use the msvs_version param: npm install --msvs_version=2015

What if the msvs_version param doesn't work?

If the msvs_version param doesn't work, it's probably because you don't have a Visual C++ 2015 build environment installed.

Install Visual C++ Build Environment

Option 1: Visual Studio 2015

  1. During VS2015 installation, select "Custom". Or, if you've already installed VS2015, go to Windows' "Uninstall or change a program" > select VS2015 from the list > click "Change" > click "Modify"
  2. Check the "Common Tools for Visual C++ 2015" option, under "Programming Languages" > "Visual C++"
  3. Finish the VS2015 installation

Option 2: Visual C++ Build Tools 2015

As an alternative to VS2015, you can install the Visual C++ Build Tools 2015 released by Microsoft:

  1. During VC++ installation, select "Custom"
  2. Check the "Windows 8.1 SDK" and "Windows 10 SDK" options
  3. Finish the VC++ installation

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:

  1. Open PowerShell
  2. Use the msvs_version param: npm install --msvs_version=2015

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

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

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

Modify your project's package.json file to include:

"config": {
  "msvs_version": 2015
}

Henceforth, every time you run npm install, for this project, the msvs_version=2015 param will automatically be included


Article Revisions

  1. Steps revised after further investigation inspired by Chuck's comment about the v120 toolset (thanks @ChuckWalbourn)
  2. Added config options
  3. Added VC++ Build Tools option
  4. Updated VC++ Build Tools link for official release
6
  • 1
    You can also install the v120 toolset by selecting "Windows 8.1 and Windows Phone 8.0/8.1 Tools" in the custom setup options for VS 2015. Commented Sep 14, 2015 at 2:08
  • @ChuckWalbourn what appears to be happening when you select the "Windows 8.1 and Windows Phone 8.0/8.1 Tools" option is, it's selecting the "Common Tools for Visual C++ 2015" option as a dependency, and that is what's actually installing the required toolset
    – 2Toad
    Commented Sep 16, 2015 at 19:36
  • I faced a situation while installing bcrypt, "npm i bcrypt --msvs_version=2013" worked for me
    – codersaif
    Commented Dec 6, 2015 at 12:47
  • I could swear I selected all the options when installing VS2015, yet, upon reading this answer and checking, I found the C++ unchecked. Agrh! Commented Mar 8, 2016 at 1:11
  • 2
    But what does one do when the build tools are actually installed?
    – Jeff
    Commented Apr 12, 2016 at 15:42
4

I wanted to add a comment to 2Toad's answer but stackoverflow doesn't let me. You can set the msvs_version globally with this command:

npm config set msvs_version 2015 --global

This saves you putting it in each projects config object.

2
  • why the downvote? setting the config globally via the command line isn't mentioned in the other answer
    – Sam
    Commented Nov 25, 2015 at 12:36
  • This answer is a bit misleading: using the npm config set msvs_version 2015 setting without the --global flag achieves the goal of not having to put it in each project's config. The --global flag is only needed if you plan on logging in with different Windows accounts, and you want that setting to apply to all accounts on that machine
    – 2Toad
    Commented Dec 18, 2015 at 19:32
2

I'll share this answer since none of the other fixes resolved my issue. I was having the same errors but setting the msvs param:

npm install --msvs_version=2015

was not solving the problem. I could see that it was looking in the wrong place for the toolset no matter what I did.

Long story short I learned that MSBuild is now packaged with Visual Studio and no longer packaged with .NET. Sure enough I had this entry in the PATH variable:

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

and consequently the wrong (old) version of MSBuild was being called. I removed this entry and added the following path which is relevant for VS2015:

C:\Program Files (x86)\MSBuild\14.0\Bin\

Problem solved.

1
  • this is the only correct answer, setting variables is not enough. set PATH=C:\Program Files (x86)\MSBuild\12.0\Bin;%PATH% or set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
    – Shrike
    Commented Sep 20, 2016 at 21:52
1

I already spend 2 days installing all VS versions...

npm install oracledb --msvs_version=2015

Return all lot of errors :

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

Using

npm install oracledb --msvs_version=2013

Return a lot of warnings, compile but doesn't work properly after.

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

This is my worst ever experience with a npm module. What a waste of time :/

2
  • I re-install VS2015, clean the system path variable with all variable in installation readme. Got all the warning but it's working properly now ... ¯_(ツ)_/¯
    – Wifsimster
    Commented Nov 7, 2016 at 13:10
  • More than a year have passed and I'm having the same problem... I'm very disappointed with this package too, if I could choose I won't be using it. Commented Jan 15, 2018 at 19:09
0

Setting version to 2015 didn't help for me. Try setting it to 2013 instead:

npm config set msvs_version 2013

or

npm config set msvs_version 2015

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.