Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10: The build tools for v120 (Platform Toolset = 'v120') cannot be found. #679

Closed
nerijusgood opened this issue Aug 2, 2015 · 66 comments
Assignees
Labels

Comments

@nerijusgood
Copy link

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 [email protected]
npm WARN optional dep failed, continuing [email protected]

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?

@perok
Copy link

perok commented Aug 4, 2015

Have you installed visual studio 2015 with visual C++? That helped for me.

@nerijusgood
Copy link
Author

The above error is with MVS 2015 C++. Could not do anything here so I completely removed MVS 2015 and installed 2013 C++.

Now it seems to have different error. The error is with too long path names (opened case in stack overflow, since its not node-gyp fault): http://stackoverflow.com/questions/31817447/windows-10-node-gyp-cannot-build-msbuild-failed-with-exit-code-1

Any ideas?

@BlackGlory
Copy link

I have same problem in Windows 10 with VS2015&SDK.
:-(

@axefrog
Copy link

axefrog commented Aug 14, 2015

If there were a +1 button, I'd be clicking it myself right now, but there's not, so I'm forced to pollute your issue with my comment. Please accept my humblest apologies. Windows 10 user. VS2015 and VS2013 both installed, and both with C++. utf-8-validate is the offender in my case too.

@musm
Copy link

musm commented Aug 14, 2015

I'm having problems with Windows 10. VS2015 community installed. I get the following error

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.   

@axefrog
Copy link

axefrog commented Aug 14, 2015

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.

@uxfed
Copy link

uxfed commented Aug 16, 2015

@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)

@jasonwilliams
Copy link
Contributor

BTW what SDK are people using?
Im still using the one from the readme, if anyone gets this working on Windows 10 i would be ever so grateful if you could write a walkrthough, step by step guide. I've been struggling with this for the past few days now

@pjquinn I now get this error instead:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(214,5): error MSB4175: The task fac
tory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll". Cou
ld 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.

Can anyone help? :(

@uxfed
Copy link

uxfed commented Aug 18, 2015

Maybe try VS2015 w/ C++ and set env variable: GYP_MSVS_VERSION=2015

I'm on win 8.1 though, not 10

@jasonwilliams
Copy link
Contributor

@pjquinn that didn't work for me :-(

@uxfed
Copy link

uxfed commented Aug 24, 2015

@jayflux I also ended up installing beta npm@3 (using 3.3.0 currently), I'm not sure which of the above finally made it work, but it does now, at least on Win 8.1

@jasonwilliams
Copy link
Contributor

@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

@zhaoyao91
Copy link

@Jayflux what version of window, vs, and sdk are you using now?

@jasonwilliams
Copy link
Contributor

@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

@nerijusgood
Copy link
Author

@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.

@zhaoyao91
Copy link

@Jayflux, thanks

Finally, it woks for me, all I need are:
windows 10 64-bit
node.js 0.12.x
python 2.7.x
vs 2013
(SDK and GYP_MSVS_VERSION are not needed)

and if both vs 2013 and vs 2015 are installed, set GYP_MSVS_VERSION=2013

I hope this will be helpful for others.

@axefrog
Copy link

axefrog commented Aug 27, 2015

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

@musm
Copy link

musm commented Aug 28, 2015

Yeah this should not be closed. For one support for VS 2015 should be available. I shouldn't have to uninstall and reinstall VS to get this thing to build

@nerijusgood nerijusgood reopened this Aug 31, 2015
@fresc81
Copy link

fresc81 commented Sep 5, 2015

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.

@jasonwilliams
Copy link
Contributor

@fresc81 is this something you could put into a pull request?
OR does there need to be some logic to check what OS you're on?

@ALL
Whats the action needed here?

@JasonPierce
Copy link

This is what worked for me on Windows 10 Pro (x64) with Visual Studio 2015: http://stackoverflow.com/q/32556295/1050784

@brynnbp
Copy link

brynnbp commented Sep 16, 2015

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.

@jasonwilliams
Copy link
Contributor

The task for this ticket is for someone to find a fully working solution for windows 10 and document it. (at the moment there are still different solutions mentioned in this thread)

This might involve getting a VM with windows 10 on it and starting from scratch.
Once we know for sure the correct steps, we need to write them into the Readme

@nullivex
Copy link

nullivex commented Oct 7, 2015

@Jayflux I am working on a blog for this currently.

I am going to document the steps I took on my computer and the steps I took on a fresh VM.

I will provide a link when it is done.

@jasonwilliams
Copy link
Contributor

Thanks @nullivex you're a hero

@jasonwilliams
Copy link
Contributor

@jasonwilliams200OK are you able to update the readme if thats the case? as i think you have the best knowledge of what to do.
I think the readme still says install VS

@ghost
Copy link

ghost commented Feb 25, 2016

@mousetraps
Copy link
Contributor

And we have a PR open (#867) to update the readme (ran into a few snags while adding to CI that we can hopefully address that in the next build tools release. So close! 😃)

@jasonwilliams
Copy link
Contributor

oh awesome, thanks @mousetraps!

@bsclifton
Copy link

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?

@bsclifton
Copy link

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 #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"

@spapaseit
Copy link

spapaseit commented May 3, 2016

I've tried everything in the workaround except for the last step, since I've never had a MSBuild\12.0 folder; my machine only has MSBuild\14.0 installed.

I keep on experiencing the following error on npm install:

error MSB4019: The imported project "C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props" was not found.

The packages utf-8-validate and bufferutil seem to be the culprits.
As you can see, it looks into the V11 folder, and I only have a v140 folder in my machine.

Noe that this doesn't happen when I run npm install from a Command Prompt with Administrator rights.

But I should be able to run this from a normal PowerShell with posh-git as well. Any ideas?

@evil-shrike
Copy link

evil-shrike commented Sep 20, 2016

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.

@hungcao181
Copy link

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.

@NicolasDorier
Copy link

NicolasDorier commented Jun 7, 2017

My problem was the MSBuild pointed by the PATH environment variable was not the expected version.

Correct one is "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (Visual Studio 2015 build tools installed)

msbuild -version

Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

14.0.25420.1

Ran again npm install, and worked like a charm.

@ira-hart
Copy link

ira-hart commented Jun 8, 2017

The fix for me was to do this in Microsoft Visual Studio 2017:
project -> Retarget_solution
Platform toolset

and then:

project -> Retarget_solution
Windows SDK version

After that, it built with no issues.

@crazysal
Copy link

crazysal commented Jun 9, 2017

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

npm install --global windows-build-tools

Installs all dependencies as needed

@saper
Copy link
Contributor

saper commented Aug 17, 2017

I believe this can be closed now.

In general the recommendation is always to use the same PlatformToolset for addons and for the node engine itself. This means the same compiler should be used to build node and addons.

Older versions of node were built with VS2013, since 6.3.0 I think VS2015 is used.

@refack refack self-assigned this Aug 17, 2017
@gibfahn
Copy link
Member

gibfahn commented Aug 19, 2017

In general the recommendation is always to use the same PlatformToolset for addons and for the node engine itself. This means the same compiler should be used to build node and addons.

Doesn't this mean in effect we only support building native modules on Windows with one version of Visual Studio?

@saper
Copy link
Contributor

saper commented Aug 19, 2017

one should not mix, currently node binaries from nodejs.org are built with VS2015 and PlatformToolkit v140. But one can easily build node yourself with own version of VisualStudio and build modules as needed.

@happygrizzly
Copy link

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.

This is twice as terrible if you don't have admin rights (installations are possible yet it might take a long time to be done) due to some corporative standards)))))

@rvagg
Copy link
Member

rvagg commented Jun 20, 2019

closing due to staleness, windows support has evolved somewhat since this was opened, please open a new issue if there's a new specific thing that can be discussed

@ashish314
Copy link

I had this similar issue on windows 10 and node 11, npm install was failing due to node-gyp rebuild command was unable to complete. I tried every solution i could find including installing mvs 2015, python 2.7 nothing worked.
Then i tried with latest node version i.e 16 and used git bash(terminal) instead of windows cmd and i don't know how but it worked. At this point i have mvs verion 2019 and 2015 installed and mvs version 2019 set in npm config.
Hope this helps..!!

@davidalbertonogueira
Copy link

What's the proper way to install node-gyp in 2022?
I'm doing npm install in https://github.com/creativetimofficial/impact-design-system/ , and I get errors pointing to this library. The error states that I have version3, but npm ls -g says that I have version9.

Links: creativetimofficial/impact-design-system#24
Latest issue that I oppened : #2688 (#2688)

@cclauss
Copy link
Contributor

cclauss commented Jun 27, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests