How to Fix node-gyp Error on Windows

how-to-fix-node-gyp-error-on-windows
Mon Sep 26 2016 09:51:56 GMT-0500 (Central Daylight Time)

I hit this problem once or twice a year and always seem to forget how easy it is to fix the problem. This blog post will ensure that not only I remember, but the entire Internet will remember the solution I use.

Here goes.

The Problem

The problem is simple: You pull down a repository that uses NPM for package management onto your Windows machine, you type npm install and you get something like this:

npm ERR! Failed at the <package>@<version> install script 'node-gyp rebuild'

or

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

This is because the project you're trying to build requires the node-gyp package to build something natively on the platform. That package required Python 2.7 and a few other pieces too.

The Solution

Simple problems sometimes get simple solutions.

Thanks to the node-gyp team, that is the case and they have documented it in the project README.

Using a PowerShell CLI instance with administrative priviledges, and use the following code:

npm install --global --production windows-build-tools

And that's it.

There is a manual option as well, but I haven't needed to use it as the first option always works for me.