node-gyp: Windows 10: The build tools for v120 (Platform Toolset = 'v120') cannot be found.

When installing package via NPM some module had dependency that fired node-gyp rebuild which spawns tons of errors:

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build t
ools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 bui
ld tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-cli
ck the solution, and then selecting "Retarget solution". [C:\Users\nerij\Projects\react-browserify-cli\node_modules\bro
wser-sync\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modul
es\utf-8-validate\build\validation.vcxproj]
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 (c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "c:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\nerij\Projects\react-browserify-cli\node_modules\browser-sync\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v2.0.1
gyp ERR! not ok
npm WARN optional dep failed, continuing bufferutil@1.1.0
npm WARN optional dep failed, continuing utf-8-validate@1.1.0

This is part of install which gets errors. I fallowed instruction on node-gyp install, however Windows 10 does not allow instal Windows 7 SDKs (I found and installed Windows 10 SDKs, with no efefct). Anyone had same issues?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 31
  • Comments: 66 (21 by maintainers)

Most upvoted comments

Guys, this worked for me; add GYP_MSVS_VERSION=2013 to your user environment variables. i.e. right-click start -> system -> advanced system settings -> environment variables -> “user variables for [username]” -> new Make sure you open a new console after doing this, so that the environment variable addition is picked up.

I have same problem in Windows 10 with VS2015&SDK. 😦

@axefrog Thank you!!!

With Windows 8.1 and VS2015 SDK/C++ installed I had to use:

GYP_MSVS_VERSION=2015

(so change the version to what you’re using)

Why would you close this without either (a) adequate documentation or (b) at least a fix to look in both locations? That’s lazy.

Glad I didn’t give up- I believe I fully understand the issue 😄 Hopefully this helps someone and @mousetraps, you might consider adding this to https://github.com/nodejs/node-gyp/pull/867 (or at least linking to this issue).

The problem

Installing Visual Studio 2013 before or alongside installing Visual Studio 2015 will corrupt the default values used for MSBuild in the Windows registry. Specifically, it corrupts what MSBuild evaluates VCTargetsPath as (incorrectly evaluating it to an older path).

Supporting data

  • A fresh install of Windows as documented by @nullivex does not have this issue when Visual Studio 2015 is installed.
  • The workaround suggested by @mousetraps does seem to help a decent number of folks. I suspect it helped because they uninstalled/re-installed, which may have fixed the registry.
  • Visual Studio is a complicated piece of software and having two side-by-side installs does cause conflicts. This thread on StackOverflow has data for different situations that customers experienced, because of which versions of Visual Studio and probably the order they installed them in.

My work-around

In my case, I had uninstalled Visual Studio 2013, but I never uninstalled/re-installed Visual Studio 2015… I only modified an existing installation.

I was able to force MSBuild to use Visual Studio 2015 by only doing the following:

  • Setting the environment variable GYP_MSVS_VERSION=2015, per the documentation
  • Running the steps @mousetraps outlined:
    • installing SDK for Windows 8.1/Windows 10
    • npm config set python python2.7
    • npm config set msvs_version 2015 --global
  • Setting the environment variable VisualStudioVersion=14.0
  • Moving my old MSBuild directory (which didn’t get uninstalled) out of the way, like so mv "C:\Program Files (x86)\MSBuild\12.0" "C:\Program Files (x86)\MSBuild\12.0_OLD"

At this point, it resolves to the correct version… although I experienced the error: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(219,5): error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll' or one of its dependencies. The system cannot find the file specified. [C:\Users\Brian\Projects\browser-laptop\node_modules\bloom-filter-cpp\build\bloom-filter-cpp.vcxproj]

For this, I copied the DLL from the MSBuild folder I renamed above. That fixed the issue. cp "C:\Program Files (x86)\MSBuild\12.0_OLD\Bin\Microsoft.Build.Tasks.v12.0.dll" "C:\Program Files (x86)\MSBuild\14.0\Bin\Microsoft.Build.Tasks.v12.0.dll"

https://www.npmjs.com/package/windows-build-tools

npm install --global windows-build-tools

Installs all dependencies as needed

Simply running npm install --msvs_version=2015 after deleting node_modules fixed this issue for me on Win7 with VS2015. I also did a set GYP_MSVS_VERSION=2015 and closed/opened console, but not sure if that’s related.

@pjquinn finally got it working by uninstalling Visual Studio 2015 and installing 2013, then i ran

set GYP_MSVS_VERSION=2013
npm install --msvs_version=2013

So 2013 deffo works on windows 10, not sure why 2015 fails

This is a nasty issue 😦 I am experiencing the same issue reported by the OP. My exact config:

  • Windows 10 (64 bit, version 1511 OS Build 10586.218)
  • GitHub shell (3.0.17.0)
  • nodejs (v5.10.1)
  • npm (3.8.3)
  • python (2.7.10)
  • Visual Studio (Community - 2015 Update 2; including Visual C++ and all sub components)

The npm install I’m running performed several compiles using node-gyp. It was originally failing because node-gyp was defaulting to V110 (which didn’t exist on my machine) C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props

I performed the steps @mousetraps outlined here, notably:

  • installing the Windows 8.1 SDK
  • installing the Windows 10 SDK
  • opening a shell, post-install, and running:
npm config set python python2.7
npm config set msvs_version 2015 --global

Just for fun, I’ve rebooted to make sure things take effect. npm install now fails with this error: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-cli ck the solution, and then selecting "Upgrade Solution...".

Notice how it’s using the path for V120, but likely passing msbuild the params for 140. I tried to work around this by doing the following:

  • setting environment variable GYP_MSVS_VERSION=2015
  • setting PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
  • setting VCTargetsPath=“C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140”

None of these work. Why is VCTargetsPath being resolved to V120, and not V140?

These official guidelines resolved my problem:

https://github.com/nodejs/node-gyp#installation https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#resolving-common-issues

For the summary, Properly install of Python2.7, C++ build tools, then walk through Resolving common issues section on the Microsoft’s nodejs guideline should help.

node-gyp: v3.4.0 Windows 10 and full VS2013 and VS2015 installed (tried on 2 machines). Setting --msvs_version=2015 and GYP_MSVS_VERSION=2015 does not help. Only after changing PATH it seems to work: set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%

for using vs2013 it’s required the similar : set PATH=C:\Program Files (x86)\MSBuild\12.0\Bin;%PATH%

how the hell should I understand which VC++ version a package require? Why node-gyp’s script can not declare it?! Why node-gyp can find a working VC++ version on machine? that’s all simply terrible.

npm config set msvs_version 2015 -g with visual studio 2015.

worked fine for me (was installing browser-sync globally)

I managed to build with VS 2015 Community Edition under Windows 10. Turns out Microsoft decided to move the C-Runtime library to be part of the Operating System. I had to manually add the new locations of the header and library files to the file located at %HOMEPATH%.node-gyp\0.12.7\common.gypi.

(...)
    # Forcibly disable -Werror.  We support a wide range of compilers, it's
    # simply not feasible to squelch all warnings, never mind that the
    # libraries in deps/ are not under our control.
    'cflags!': ['-Werror'],
    'msvs_settings': {
      'VCCLCompilerTool': {
        'StringPooling': 'true', # pool string literals
        'DebugInformationFormat': 3, # Generate a PDB
        'WarningLevel': 3,
        'BufferSecurityCheck': 'true',
        'ExceptionHandling': 1, # /EHsc
        'SuppressStartupBanner': 'true',
        'WarnAsError': 'false',
        # ADDED
        'AdditionalIncludeDirectories': [ 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt' ],
      },
      'VCLibrarianTool': {
      },
      'VCLinkerTool': {
        'conditions': [
          ['target_arch=="ia32"', {
            'TargetMachine' : 1, # /MACHINE:X86
            # ADDED
            'AdditionalLibraryDirectories': [ 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x86' ],
            'target_conditions': [
              ['_type=="executable"', {
                'AdditionalOptions': [ '/SubSystem:Console,"5.01"' ],
              }],
            ],
          }],
          ['target_arch=="x64"', {
            'TargetMachine' : 17, # /MACHINE:AMD64
            # ADDED
            'AdditionalLibraryDirectories': [ 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64' ],
            'target_conditions': [
              ['_type=="executable"', {
                'AdditionalOptions': [ '/SubSystem:Console,"5.02"' ],
              }],
            ],
          }],
        ],
        'GenerateDebugInformation': 'true',
        'RandomizedBaseAddress': 2, # enable ASLR
        'DataExecutionPrevention': 2, # enable DEP
        'AllowIsolation': 'true',
        'SuppressStartupBanner': 'true',
      },
    },
    'msvs_disabled_warnings': [4351, 4355, 4800],
(...)

I didn’t check why VS doesn’t find it’s C-Runtime by itself and there may be a fancier solution for this. For example I have to manually maintain the paths. But I was able to build socket.io with all dependencies.

@zhaoyao91 Windows 10 Visual Studio 2013 I have both SDK 7.1 and SDK 10 installed, I think its using 10 (any way for me to confirm this)? set GYP_MSVS_VERSION=2013 npm install --msvs_version=2013

According to https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245 the better approach is to run npm config set msvs_version 2015 --global once, instead of defining environment variable. Also, no need to install full blown VS now, just the “Build Tools” which has 2015 compiler, SDKs etc.

@Jayflux Okay here it is. Took all afternoon but I got this working pretty flawlessly on a new installation. I also got my local desktop working.

Here is the blog I put together about the issue: http://www.serverpals.com/blog/building-using-node-gyp-with-visual-studio-express-2015-on-windows-10-pro-x64

It is lengthy but it covers the entire installation process.

I would say the highlights are the following

  • Install the latest npm which is 3.3.6 at the time of writing
  • Install Visual Studio Community 2015 Edition. Select Visual C++ during the installation (might not be completely neccessary)
  • Set the environment variable GYP_MSVS_VERSION=2015
  • Run the command prompt as Administrator

Hopefully this helps someone!

@Jayflux confirmed. Your method works. I completely removed all Microsoft associated build tools from Add/Remove Program panel. Then fresh clean install of VS2013 with no addons.

set GYP_MSVS_VERSION=2013
npm install --msvs_version=2013

It works. Tho, npm install --msvs_version=2013 dropped bunch of erros… I don’t care - works.