74

Here's what I've done so far on my x64 OS:

  • Installed Python (v2.7 --specifically 2.7.6) and added it to the system path (C:\Python27)

  • Installed MS VS C++ 2010 Express Version (I already had VS 2012 but without the C++ component)

  • Installed the compiler update for Windows SDK 7.1

  • Successfully executed node-gyp configure (from my add-on directory under nodejs\node_modules where binding.gyp is located)

  • ran node-gyp build (as administrator)** This is what crashed, leaving me with:

this error:

C:\Program Files\nodejs\node_modules\msnodesql>node-gyp build
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build, please add the   "/m" switch.

LINK : fatal error LNK1181: cannot open input file 'kernel32.lib' [C:\Program Files\nodejs\node_modules\msnodesql\build\sqlserver.vcxproj]

gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\RNelson\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Users\\RNelson\\AppData\\Roaming\\npm\\node_modules\\node-      gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd C:\Program Files\nodejs\node_modules\msnodesql
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok

Any ideas as to what is going on?

5
  • can you paste the text of error.not so clear to read
    – Pradheep
    Commented Feb 4, 2014 at 19:55
  • @Dalorzo: I ended up solving this!! Will post solution shortly here. It took a lot of work and will take some time to post the details. Stay tuned.
    – Rachael
    Commented Feb 26, 2014 at 20:11
  • 5
    and the solution was ...
    – backdesk
    Commented Mar 12, 2014 at 20:46
  • @Rachael What was your solution?
    – ton1
    Commented Dec 15, 2015 at 14:30
  • @Juntae , see accepted.
    – Rachael
    Commented Dec 15, 2015 at 18:00

13 Answers 13

49

I had a similar problem. I found that this switch helped me

--msvs_version=2012

so for example

npm install --msvs_version=2012 <package>
3
  • 2
    I confirm that works for VS 2013 as well. Instead just use --msvs_version=2013 Commented Dec 8, 2014 at 3:42
  • 2
    Visual Studio 2015 didn't work for me, but 2013 did. This indicates to me that you need node tools for visual studio installed. github.com/Microsoft/nodejstools Commented Aug 5, 2015 at 22:42
  • The question is about rebuilding node-gyp -- how does this switch apply in that case?
    – meetar
    Commented Sep 11, 2015 at 21:02
38

npm config set msvs_version 2013 --global worked for me as I use VS node tools and you dont need to specify msvs_version each time you do an npm install.

I had an issue whereby npm's config (c:\Users\username\ .npmrc) has an entry msvs_version=2012 which was out of date.

5
  • 5
    REALLY nice catch! I am going to try the install again with this to test it on my machine. Looks like the heart of the issue here! Maybe you should add this to the npm page where it can reach the most people?
    – Rachael
    Commented Dec 19, 2014 at 17:55
  • saved me again on a new machine.
    – Rachael
    Commented Sep 12, 2015 at 19:11
  • Late to the party, but can you elaborate on why setting the Visual Studio version to 2013 was successful although he had VS 2010 installed? What am I missing?
    – lux
    Commented Dec 16, 2015 at 2:30
  • What is .npmrc...??? I couldn't find one on my laptop... Please help... ;) Commented Aug 4, 2016 at 10:26
  • You can't do this anymore, the message is npm ERR! 'msvs_version' is not a valid npm option
    – gene b.
    Commented Feb 21, 2023 at 17:46
19

After spending a while to get this to work (for me accepted answer didn't work, for me it's just half solution) i did following:

  1. Sadly, you must have visual studio (i installed express edition 2013 for DESKTOP)

  2. Installed python 2.7.3 (you don't have to set any environment variables)

  3. Run cmd as administrator and go to you project root (where is you package.json file)

  4. First run: npm config set python C:\Python27\python.exe

  5. Then: npm install -msvs_version=2013

The trick is in command npm config set python ...path_to_python_exe... which will be provided by npm to dependency which needs python i guess. I don't know why setting python as env variable is not enough.

3
  • 1
    I wish this had made a difference :(
    – Jon Biz
    Commented Dec 16, 2014 at 5:21
  • @JonBiz, what kind of error you get after following above steps?
    – Srle
    Commented Dec 16, 2014 at 9:36
  • @Kwoxer, I just looked and I happen to had installed Python 2.7.6. I would try using that version rather than maybe some incompatible older version? I did add my python directory to the system path.
    – Rachael
    Commented Apr 6, 2015 at 20:06
15

If all above did not work (my case - Windows10 64bit)

Delete C:\Users\user_name\.node-gyp

Delete %AppData%/npm

Delete %AppData%/npm-cache

And install node-gyp again

Following instruction on node-gyp page

I chose Option 1 npm install --global --production windows-build-tools

2
  • 6
    npm install --global --production windows-build-tools seems to be the fastest and the clearest way (also on Win10 x64)
    – thybzi
    Commented Aug 30, 2017 at 12:02
  • 1
    I am on win10 64, and this is the only way to solve the problem.
    – Zhang Buzz
    Commented Feb 8, 2018 at 6:45
9

For installing node-gyp in windows or any other OS

First you may have to download the node-gyp by

$ npm install -g node-gyp-install

Then install by

$ npm install -g node-gyp

you may need to do the above procedure as root/administrartor.

4

I had this same error now in 2015 when trying to install Keystone and I ran through all you told me but it didn't work on it's own. At the end, I just had to run the command

"C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\SetEnv.CMD" /Release /x64

to set up the environment before running the command. (Don't freak out when it turns your window text green, it's working). So yeah I'd do the installations and set up environment variables in the same way everywhere on the internet suggests but make sure to run the above command before running any other command. It probably won't be useful to you, but hopefully it's useful to someone else. If that still doesn't work, MSVS version 2010 worked for me, so install that version and use the flag -msvs_version=2010 when running the npm command.

4
  • Angie if you still have the error message that would be great to see!
    – Rachael
    Commented Jul 2, 2015 at 15:25
  • @Rachael yeap! i'll get back to you asap!
    – Angie
    Commented Jul 2, 2015 at 15:42
  • hmm, now my node-gyp rebuild seems to hang somewhere. I'll have to get back to you later @Rachael sorry :(
    – Angie
    Commented Jul 2, 2015 at 16:55
  • i don't have a Microsoft SDKs folder. Commented Aug 9, 2021 at 8:33
1

For me the solution that worked with VS express was to simply install Visual Studio 2013 Express for desktop (which is the only one that gives you a developer command prompt as of 2013 version). Open developer command prompt (elevated) and run NPM install commands. This did not require any special --msvs_version arguments, it just worked.

1

I came across this problem myself, and this is how I solved it using Visual Studio 2010:

Install following packages

Use npm install from the Windows SDK command prompt (you need this because it sets additional environment variables).

Source: node-gyp instructions for VS2010

1

For me (Windows 7 64bit),

I struggled with this issue for half of a day Finally It worked.

On my way :

  1. At control panel, I deleted all Python, Microsoft Visual Studio, Microsoft Redistributable, and something about I installed to solve this.

  2. Window Update and restart.

  3. Installed Python27, and Visual Studio 2013 with no setting env-val

  4. npm install node-gyp -g

  5. I got an error same thing, but after npm config set msvs_version 2013 --global , It works.
0

there is an easy to use windows build tools global node package. You could try this.

0

I was also getting similar issues and here is what worked for me.

  • Removed Python and Visual Studio
  • Installed Python 27 and Microsoft Visual Studio with "Desktop development with C++"
  • Setting the python path npm config set python /path/to/executable/python
  • npm install node-gyp -g
  • node-gyp configure --msvs_version=2013
0

Just had the same problem. Install NVM (Node version manager) and then open your CMD and use NVM install node@ followed by the version your dependencies need. If you don't know what version you might need try playing around with different version I reverted my Node back to version 14.15.0 and then used NPM install and everything ran smoothly! Hope this helps!

0

Install chocolatey in PowerShell with administrator permissions:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Install required versions of the Microsoft Build Tools for Visual Studio: https://community.chocolatey.org/packages?q=visual+studio+tools

In my case:

choco install visualstudio2019buildtools

And install workload:

cinst visualstudio2019-workload-vctools

Worked with node 16.16.0 If used nvm. Reinstall node version. And all will work fine.

Not the answer you're looking for? Browse other questions tagged or ask your own question.