Npm install fails in node-gyp

March 6, 2023    Web Development NPM Node

Npm install fails in node-gyp in Windows WSL2

I had an older app and npm install failed in the node-gyp step. There were several steps I took to solve this issue.action-area

Use Visual Studio 2022 tools

You may have to change configuration to point to the VS installation you have or install the tools .

node-gyp configure --msvs_version=2022 worked for me after running the VS installer modify.

Possible Error

I was getting this error until I followed the instructions in the node-gyp message below and installed the Visual Studio “Desktop development with C++” workload.

gyp ERR! find VS msvs_version was set from command line or npm config        
gyp ERR! find VS - looking for Visual Studio version 2022
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt      
gyp ERR! find VS checking VS2022 (17.5.33424.131) found at:
gyp ERR! find VS "C:\Program Files\Microsoft Visual Studio\2022\Professional"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v143
gyp ERR! find VS - missing any Windows SDK
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************

Install Python3 and Set the environment

You also need Python3 installed. In WSL, check if it’s there with which python3, echo $Python. If the env variable isn’t set then add export PYTHON=/usr/bin/python3 to the ~/.bashrc file.

make sure you node and npm versions are correct

Then I used nvm to update node. I needed NodeJs lts/fermium ( https://stackoverflow.com/questions/66878986/npm-err-code-127-gyp-err-stack-error-command-failed#:~:text=The%20issue%20is%20that%20node-gyp%20tries%20to%20build,with%20the%20current%20Node%20version%20on%20your%20system.) , the newer versions failed. You can install and use multiple Node versions using nvm.

nvm install lts/fermium

nvm use lts/fermium (you may need to run every time you start up WSL) nvm alias default lts/fermium should persist it

npm install

Success!

via GIPHY



Watch the Story for Good News
I gladly accept BTC Lightning Network tips at [email protected]

Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)

Use Brave

Also check out my Resources Page for referrals that would help me.


Swan logo
Use Swan Bitcoin to onramp with low fees and automatic daily cost averaging and get $10 in BTC when you sign up.