Home > IT, JavaScript, Software Development > Quick NPM tip and a little rant about node-gyp

Quick NPM tip and a little rant about node-gyp

Wednesday, July 1st, 2015

Before I start explaining why I’m writing this, here’s my NPM tip of the day: if you encounter errors pertaining to node-gyp “rebuild”, while trying to install an NPM package, then before wasting precious hours of your life, just try to install using the –no-optional flag; if you’re in luck, that’ll just work (as it did for me in most cases).

Now what the heck is node-gyp? That’s a fair question to ask. As they put it in their readme it’s a “cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js … and takes away the pain of dealing with various differences in build platforms”.

Well the way I now see it, it might just do what they say.. for people who need/care about that, but for the rest of the world and especially people like me who just want to install an npm package and get on with their life.. it’s just trouble and needless time waste.

Sometimes when you try to install an NPM package, there will be some dependency in the tree that requires to be built specifically for your platform and at that point, node-gyp (which is one of the dependencies of NPM itself) might come into play. The issue is that to be able to do its job, node-gyp has some prereqs that vary from OS to OS and those prereqs are not part of node/NPM (you’ll soon understand why :p). If you’re one of the good guys and use Linux (you should… and I should too but can’t) then you’ll be alright: python + make will make your day (you’ll also be fine with OSX).

Unfortunately, if you’re a sad panda working on a Windows box just like me, then tough luck!

Here’s a little overview of the ‘light/small’ requirements that node-gyp has on Windows 8+:

  • Python (2.7.x and NOT 3.x+): ok just with this one I already dislike node-gyp
  • Microsoft Visual Studio C++ 2013: ok, now I hate it. Do I really need 7GB just to get an npm dependency on my machine? Wtf (pre-compiled binaries FTW, if I wanted to compile everything myself on my machine, I’d still be using gentoo..)
  • and last but not least, for 64-bit builds… Windows SDK: are you kidding me?!!

Assuming that you’re motivated, then you’ll go ahead and install these.. try again and… still get the same error?! Gee… Well the thing is that quite some people have encountered this problem and have hopped through all kinds of hoops to finally get it to work. Some have had success by uninstalling all Visual C++ redistributable packages (any gamers around here?), reinstalling node-gyp’s dependencies in a specific order, adding environment variables and whatnot..

In my case I was pretty happy to discover that in all cases, the dependencies that needed node-gyp were optional (e.g., for babel, browserify and some others), so simply avoiding them was fine. If you really do need node-gyp to work then I pity you and your disk space ^^. Just take a look at some of these links and may the force be with you.

What also sucks is that npm install rolls back on error even for optional dependencies although it’s not supposed to..

If you enjoyed this post, make sure you subscribe to my RSS feed!


  1. Thanks for the tip. node-gyp is a nightmare on Windows. I never have issues on Mac or nix.

    I don’t have the unfortunate displeasure of having to use windows, but other team members do, so when they try doing a maven build, they are running into this problem all the time. Even with all of the b.s. dependencies installed on their system, npm hangs so often on windows that it has trouble ever getting all of the npm packages installed. So end up deleting the node_modules directory, and trying again, crossing fingers and praying to the windows/npm gods. We get a 20% success rate on NPM being able to get through its install on windows. Once it’s done the first time, its fine, but getting through that initial install in next to impossible.

    Comment by Jeff — 2015-10-20 @ 18:32
  2. Going through the pain and agony of node-gyp right now. I too need to install this festering pile of shit Visual Studio and/or Windows SDK just for one dependency, but there are always other problems. I am about to give up and dump nodejs alltogether

    Comment by bluewalrus — 2015-11-25 @ 11:10
  3. So far I’ve been quite lucky and using –no-optional has always spared me the pain of dealing with node-gyp. Most of the time dependencies that are native are optional. They probably bring something to the table, but I can certainly live without that so far =)

    Comment by Sébastien — 2015-11-25 @ 13:49

RSS feed for comments on this post. TrackBack URL

Leave a comment