NPM native builds with only Visual Studio 2013 ins

2020-06-12 02:42发布

I've got a clean install of Windows with Visual Studio 2013 Pro installed, along with current versions of Python, node and npm.

I'm trying to install the pg npm package, but it requires a native build and is failing:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2012 (Platform Toolset = 'v110') cannot be found. To build using the v110 build tools, please install Visual Studio 2012 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 "Upgrade Solution...". [C:\Users\Aaron\AppData\Roaming\npm\node_modules\pg\build\binding.vcxproj]

I can't seem to find Build tools for Visual Studio 2012 as described, and I'd certainly prefer to not need to install VS2012 just for this one need. Is there a way to force the install and build to use the available 2013 compiler/tools, without changing the code of the package?

I couldn't find anyone describing this specific problem and a solution using my Googlefu.

5条回答
够拽才男人
2楼-- · 2020-06-12 03:14

Updated node-gyp to the latest version (1.0.2) by: npm install node-gyp -g

Note that you also have to update the node-gyp that is internally used by node

Now, node-gyp will support your Visual Studio 2013 - you can check in the <npm-cache>/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py, in _CreateVersion method.

However, the native modules still won't build, giving an error that some include files are missing (ones from Windows SDK, like say winsock2.h). That is because Visual Studio 2013 is bundled with 7.1A SDK as the default. But default Toolset setting is 'v120', which expects the 8.1 SDK (which needs to be installed additionally).

To build with just the stock VS 2013, you need to change what toolset is being selected. You can do that by modifying ~/.node-gyp/common.gypi file (idea taken from here), and changing the toolset to 'v120_xp' instead (which will use the bundled 7.1A SDK):

{ ... 'target_defaults': { ... 'configurations': { ... 'Release': { 'conditions': [ ['target_arch=="x64"', { 'msvs_configuration_platform': 'x64', 'msbuild_toolset': 'v120_xp' <--- THIS LINE! }], } } } }

Voila - now the native npm modules will compile with the stock Visual Studio 2013 install!

查看更多
贼婆χ
3楼-- · 2020-06-12 03:20

I have too clean install of Windows 8.1 (64bit) Pro with Visual Studio 2013 only (no previous version of VS, although some components came with SQL Server 2014). The npm install command failed with similar error.

So I tried to specify VS version

npm install --msvs_version=2013 <package>

It started correctly using Platform Toolset 'v120' but the build failed with the following error (note the V110 used in the path for targets):

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets(44,5): error MSB8020: The builds tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install v120 to build using the v120 build tools.

I went to the path c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\ and found there two subfolders: V110 and V120.

To correct the path used for targets I had to set environment variable like this:

set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120

Then the package got installed.

For reference, the versions:
VS 2013 Premium
Python 2.7.8
C:\Windows\system32>npm version { http_parser: '1.0', node: '0.10.29', v8: '3.14.5.9', ares: '1.9.0-DEV', uv: '0.10.27', zlib: '1.2.3', modules: '11', openssl: '1.0.1h', npm: '1.4.14' }

查看更多
Melony?
4楼-- · 2020-06-12 03:21

I was having similar errors with VS2015 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.

查看更多
混吃等死
5楼-- · 2020-06-12 03:23
npm config set msvs_version 2013 --global
查看更多
Anthone
6楼-- · 2020-06-12 03:26

What helped me is to specify environment variable GYP_MSVS_VERSION to to use correct VS
you can set it in Control center or in console before running npm, so for 2013 it is

set GYP_MSVS_VERSION=2013

and for 2015 you use

set GYP_MSVS_VERSION=2015

With free VS 2013 or 2015 community edition it should be the easiest way.

PS
I believe for VS 2013 Express you should use

set GYP_MSVS_VERSION=2013e

where e tells npm to use express version

查看更多
登录 后发表回答