Node packages not building on Windows 8.1 - Missin

2019-01-13 07:27发布

问题:

NPM packages are not building on Windows 8.1 - failing with following error,

error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

I have tried the following,

  • Setting an evironment variable VCTargetsPath to C:\Program Files (x86)\MSBuild\12.0\ (The error changes accordingly but there is no Microsoft.Cpp.Default.props with the 2012 build tools).
  • Installing a VisualStudio 2010 environment (uninstalled then installed in the correct order) according to this answer
  • Completely removed VisualStudio 2010 and tried a VisualStudio 2012 instead, which should work according to the Node-gyp wiki
  • Added registry keys according to this answer
  • Tried using the Windows 7.1 SDK command prompt according to this answer
  • Tried setting VisualStudioVersion before running npm according to this answer
  • Tried passing --msvs_version=2012 to npm according to this answer

None of the above have worked.

I've spent ages on this already. Does anyone have a definite answer that works?

回答1:

The quick fix for me was this:

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


回答2:

Finally Microsoft is providing much better solution to VS.



回答3:

I just wanted to update this question with the latest answer. You now do not need to install Visual Studio.

Source: https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245

Instructions below in case the source goes down.

  1. Install VC++ Build Tools Technical Preview using the Default Install option.

    [Windows 7 only] requires .NET Framework 4.5.1

  2. Install Python 2.7, and add it to your PATH: npm config set python python2.7

  3. Launch cmd and run: npm config set msvs_version 2015 --global (this is instead of lnpm install [package name] --msvs_version=2015l every time.)



回答4:

So it is 2.47am - figured it out.

Although the node-gyp site seems to suggest using Visual Studio 2010 or 2012, instead for Windows 8.1, install Visual Studio Express 2013 for Windows Desktop as discussed in this issue.



回答5:

Setting the following fixed the problem for me

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

As mentioned on this forum



回答6:

A quick note for people who installed:

  1. Visual Studio 2012 (Express)

  2. MSBuild 2012

with the issue of:

  1. MSBuild loads Microsoft.Cpp.Default.props

  2. MSBuild cannot load Microsoft.Cpp.props

The solution is here: set parameter of MSBuild: /property:VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110"



回答7:

This is the same issue as described here

NPM native builds with only Visual Studio 2013 installed

If you have a version of VS2013 installed set this environment variable before running the npm command:

set GYP_MSVS_VERSION=2013

or for VS2012

set GYP_MSVS_VERSION=2012 

background reading: https://github.com/Automattic/socket.io/issues/1151



回答8:

Just in case people encounter this issue again, the issue got resolved in my case when I did a

npm install -g --production windows-build-tools

Link for reference

Related question