NPM native builds with only Visual Studio 2013 installed

后端 未结 5 1250
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 04:27

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

相关标签:
5条回答
  • 2021-02-14 04:54

    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!

    0 讨论(0)
  • 2021-02-14 04:59

    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' }

    0 讨论(0)
  • 2021-02-14 05:00

    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

    0 讨论(0)
  • 2021-02-14 05:01
    npm config set msvs_version 2013 --global
    
    0 讨论(0)
  • 2021-02-14 05: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.

    0 讨论(0)
提交回复
热议问题