How can I solve error gypgyp ERR!ERR! find VSfind VS msvs_version not set from command line or npm config?

TL;DR

Use the Visual Studio Installer to get the Desktop development with C++ workload in one of the Visual Studio versions you have installed in your machine:

VS workloads

Reason/Details

Reading through the log, the main error is due to this:

msvs_version not set from command line or npm config

After this one you find a few of these:

"Visual Studio C++ core features" missing

And later:

You need to install the latest version of Visual Studio including the "Desktop development with C++" workload.

For more information consult the documentation at:

VS https://github.com/nodejs/node-gyp#on-windows

Finally:

Could not find any Visual Studio installation to use

So to solve the problem, you just need to get "Desktop development with C++" workload.

If you have a Visual Studio version installed

  1. open Visual Studio Installer (Win + search for it)
  2. on the list displayed with all Visual Studio Installations you have in your PC, press the Modify button of one of them (preferably the latest version)
  3. on the Workloads grid/list select the checkbox with Desktop development with C++
  4. Press one of the Install buttons

gyp will then find that version and use it:

gyp info find Python using Python version 3.8.1 found at "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\python.exe"

gyp info find VS using VS2019 (16.4.29709.97) found at:

gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\

With NO Visual Studio installed

Disclaimer: I did not test any of these solutions.

Alternative 1

As Hamid Jolany's answer suggests, on an admin shell, simply install the build tools package globally (node-gyp README):

npm i -g windows-build-tools

Alternative 2

Ragavan's idea/answer for avoiding installing Visual Studio has some logic:

  1. verify if you have VS build tools by running npm config get msvs_version (if you have, skip to step 4 and attempt setting the environment variables)
  2. if not installed, get the VS build tools latest version exe and install it (Ragavan's idea was with or Microsoft Build Tools 2015)
  3. run npm config set msvs_version 2019 --global (or npm config set msvs_version 2015 --global according to Ragavan's idea)
  4. (optional? I have VS installed and do not have this variable declared) set the VCTargetsPathenvironment variable (Win + search for var) to the appropriate path (e.g. C:\Program Files (x86)\MSBuild\Microsoft\Portable\v5.0) or through Run as Admin terminal, as in Ragavan's idea with the 2015 Build Tools:
  • set VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140"
  • or in Powershell: $env:VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

Side notes:

  • a previous error might be resolved by installing Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019;
  • you might also want to restart after installing any of the above

Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).

Full Guidance in GitHub


use this command before "npm install"

npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe

changing \Enterprise\ to \Community\ worked for me.


Visual Studio Installer -> Modify Installed(Visual Studio Community 2019) -> Workloads(tab) -> [x] Desktop development with C++ -> Install