55

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?

Community
  • 1
  • 1
Brendan
  • 18,771
  • 17
  • 83
  • 114
  • 1
    It is located in the C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110 directory. Put there by the VS2012 installer. VCTargetsPath needs to point there. – Hans Passant Jan 12 '14 at 00:38
  • 1
    I tried this as well, it actually requires the path without the `V11.0` on the end but it still did not work ... – Brendan Jan 12 '14 at 01:16
  • 1
    Got something similar, but using VS 2013 on Windows 7. To solve it, I used the "Developer Command Prompt for VS2013" to run `npm install`. – yoneal Dec 01 '14 at 02:21

8 Answers8

51

The quick fix for me was this:

set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120
npm install
AVarabei
  • 531
  • 4
  • 4
  • 3
    And if this folder doesn't exist on your machine install the latest VS Community IDE https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx and restart. This new folder will be set by default: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140. – Richard Oct 21 '15 at 13:29
  • 8
    In my case, had to switch V120 to V140 for this to work. Make sure to actually check where the directory path leads in explorer. – ericgrosse Nov 13 '15 at 17:51
  • This quick fix works also to make node-openzwave-shared compile (https://github.com/OpenZWave/node-openzwave-shared) – Ashbay May 19 '18 at 08:52
  • PowerShell version: `[Environment]::SetEnvironmentVariable("VCTargetsPath", "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140", "Machine")` – Nameless Feb 04 '19 at 06:54
16

Finally Microsoft is providing much better solution to VS.

igor
  • 5,351
  • 2
  • 26
  • 22
  • 1
    yup, looks like that helps regardless of other VS stuff preinstalled – rudnev Nov 18 '15 at 15:38
  • 3
    Direct link for Visual C++ Build Tools (the subject of the GitHub comment linked above): http://landinghub.visualstudio.com/visual-cpp-build-tools – apardoe Jun 10 '16 at 20:53
  • 3
    New link to download build tools https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017 – Gavin Dec 06 '18 at 00:05
10

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

Antoine
  • 607
  • 7
  • 10
  • 1
    The VC++ Build Tools link above is broken. Better link is here: http://landinghub.visualstudio.com/visual-cpp-build-tools – apardoe Jun 10 '16 at 20:54
5

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.

Brendan
  • 18,771
  • 17
  • 83
  • 114
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

kromar
  • 51
  • 1
  • 2
  • 1
    Where to specify `/property` ? If specified to `npm install` it is not passed to MSBuild.. – eXavier Jul 29 '14 at 09:44
  • 1
    You can edit `C:\Windows\Microsoft.NET\Framework\v\msbuild.rsp` to set up global MSBuild properties. – Tom Mayfield Dec 21 '14 at 07:40
  • I can't edit C:\Windows\Microsoft.NET\Framework\v\msbuild.rsp. I get the warning, 'Please check this file is opened in another program' But I don't have any other program running. – Kumar S Oct 11 '16 at 04:26
3

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"

DrKNa
  • 55
  • 1
  • 8
  • I have the same issue (1) but with Visual Studio 2015. `The imported project "C:\Microsoft.Cpp.Default.props" was not found.` So i recon i should use `C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140` (the path exists) but where to set this MSBuild parameter? – Barry Staes Feb 04 '16 at 07:54
1

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

Community
  • 1
  • 1
mhanney
  • 465
  • 2
  • 11
1

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

Cy Pangilinan
  • 562
  • 1
  • 7
  • 22