npm install that requires node-gyp fails on Windows

56,018

Solution 1

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 !

Solution 2

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!

Solution 3

I couldn't find my solution anywhere else, so thought I'd share.

Running node v10.16.3 on Windows 10

Install windows-build-tools -

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

Set the python path explicitly in C:\Users[your username].npmrc - In my case, this is like so:

python=c:\users\akeel\.windows-build-tools\python27\python

Solution 4

Started Working For Me

Nothing work for me (installed msvs_version 2017,2015)

Noticed

node-gyp error comes from python path and msvsc path

npm config list

Output (set correct installed path and msvs)

; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.12.0 node/v12.9.0 win32 ia32"

; userconfig C:\Users\balaji\.npmrc
init-author-name = "Balaji"
init-license = "MIT"
msvs_version = "2017"
node_gyp = "C:\\Users\\balaji\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js"
python = "C:\\Users\\balaji\\.windows-build-tools\\python27/python.exe"

; globalconfig C:\Users\balaji\AppData\Roaming\npm\etc\npmrc

; builtin config undefined
prefix = "C:\\Users\\balaji\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files (x86)\nodejs\node.exe
; cwd = G:\all clients project\2020\anware
; HOME = C:\Users\balaji
; "npm config ls -l" to show all defaults.

To Set globaly(eg)

npm config -g set msvs_version 2015

To Set localy (eg)

npm config  set msvs_version 2015

Path correction

 npm config set python /path/to/executable/python

for those who Not installed yet(it install msvsc and python)

npm install -g windows-build-tools

after install check above givn tips such as path and version everything

happy coding....

detail info updated https://stackoverflow.com/a/68630586/11624647

Share:
56,018
Marek Lisý
Author by

Marek Lisý

Web apps developer, IT student & free time game dev. Music lover & creator. Philosophy & religion commentator. Depressionist. Sport freak. Future maths & IT teacher. Stack Overflow exception successfully thrown at C#, Java, PHP (+Nette), JS+jQuery, Android & Python. #SOreadytohelp

Updated on July 18, 2022

Comments

  • Marek Lisý
    Marek Lisý almost 2 years

    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?

  • Prasad
    Prasad about 8 years
    this is why windows user are not happy with node-gyp rebuild . Brilliant solution itself is too Big . Unhappy with the nodegyp Crap
  • Bas Slagter
    Bas Slagter over 7 years
  • phil_lgr
    phil_lgr over 7 years
    For me (windows 10 node 6.2.0), npm config -g set msvs_version 2013 worked when 2015 and 2012 didn't (I installed VS 2013, 2012, and 2015)
  • edzillion
    edzillion almost 5 years
    Warning This method force rebooted my machine and I had unsaved files, which I lost. Windows 8.1 edit: omg thankyou vscode it was still there when I opened the folder.
  • Ahmad Maleki
    Ahmad Maleki almost 5 years
    If the installation process got stuck somewhere, use the version 4.0.0 instead npm install --global --production [email protected]. Credit goes to: github.com/felixrieseberg/windows-build-tools/issues/…
  • Toby Caulk
    Toby Caulk about 2 years
    Also make sure the msbuild_path variable is setup properly in your .npmrc! I spent literally days debugging a project that wouldn't build properly only to find out that my msbuild_path was pointing to the wrong version of msbuild