Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install that requires node-gyp fails on Windows

I have a NPM project that uses bufferutils and utf-8-validate, both requiring node-gyp to install them. When I do npm install, I get following error:

> [email protected] install C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil                        > node-gyp rebuild                                                                                                C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil {git}{hg}                                         {lamb} if not defined npm_config_node_gyp (node "C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\bin\node-g yp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )                         Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.       bufferutil.cc                                                                                                 C:\Users\Marek\.node-gyp\5.1.1\include\node\v8.h(18): fatal error C1083: Cannot open include file: 'stddef.h':   No such file or directory [C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil\build\bufferutil.vcx  proj]                                                                                                           gyp ERR! build error                                                                                            gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1            gyp ERR! stack     at ChildProcess.onExit (C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\node_modules\nod e-gyp\lib\build.js:276:23)                                                                                      gyp ERR! stack     at emitTwo (events.js:87:13)                                                                 gyp ERR! stack     at ChildProcess.emit (events.js:172:7)                                                       gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)                    gyp ERR! System Windows_NT 10.0.10586                                                                           gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Marek\\AppData\\Roaming\\npm\\node_modules\\ npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"                                                        gyp ERR! cwd C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil                                      gyp ERR! node -v v5.1.1                                                                                         gyp ERR! node-gyp -v v3.2.1                                                                                     gyp ERR! not ok                                                                                                 npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`                                  npm WARN install:[email protected] Exit status 1                        

Previously it failed because of Python 2.7 not installed, now it is this. It's causing me headaches. What should I do about this?

like image 805
Marek Lisý Avatar asked Feb 09 '16 13:02

Marek Lisý


People also ask

What is npm install node-gyp?

node-gyp-install. Afterwards installing native modules that uses node-gyp using iojs should just work. node-gyp-install. npm install level # does not explode \o/ Per default node-gyp-install will install header files for your current node version.

Why npm is not working on Windows?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.


2 Answers

The answer below stands for a manual installation, but there is a much simpler way : the automatic install.

Open Powershell as admin and run npm install -g windows-build-tools.

The install takes time but it worked like a charm for me !

like image 96
Manuel Beaudru Avatar answered Sep 25 '22 17:09

Manuel Beaudru


I found this brilliant solution on GitHub:

  1. Your OS MUST be Windows
  2. Check that python is in your path by writting python --version in the console. If not then
  3. Download python 2.7 (I recommend chocolatey (choco install python2 -y)) and add python.exe to your PATH variable.
  4. Aren't you on Windows 7? Skip 5 and 6.
  5. Check that you have .NET 4.5.1+ installed. If not then
  6. Download and install .NET 4.5.1 (.NET 4.5.2 will also work just fine)
  7. Download Microsoft Visual C++ Build Tools 2015 Technical Preview
  8. Use custom install. Install the Windows 8.1 SDK if you haven't already. Apparently, it doesn't matter what OS you're on. You just need the Windows 8.1 SDK.
  9. Set the npm config variable msvs_version to 2015: npm config -g set msvs_version 2015
  10. Do npm i in what-ever project with node-gyp as a dependency without seeing weird error messages

My nightmares are gone!

like image 42
Marek Lisý Avatar answered Sep 23 '22 17:09

Marek Lisý