node-gyp configure got "gyp ERR! find VS"

66,233

Solution 1

You do not have to install Visual Studio, just install the windows build tools:

  1. run CMD as Admin
  2. run npm install --g --production windows-build-tools

This should fix that.

[1]: https://i.stack.imgur.com/31D1U.png

Solution 2

There are 2 aspects to this error. Now in 2022, if you have installed Visual Studio 2022, even after installing Desktop development with C++ or the build tools it still wont work.

Few things you need to do even after installation. npm config get python should be set to Python 3.x --> npm config set python C:\Python310\python.exe

npm config get msvs_version should be using 2022 --> npm config set msvs_version 2022 --global

Additionally you can set npm config set msbuild_path "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe"

your VCINSTALLDIR ENV variable should be set to C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\

VCINSTALLDIR

In some case it still wont work, then you can follow the additional steps, visit the folder of your Node.js exe installation, should be same even for an nvm node version; https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md

cd "C:\Program Files\nodejs"
cd node_modules\npm\node_modules\@npmcli\run-script

npm install node-gyp@latest

Solution 3

Open your Visual Studio & then in 'search box' search VS 2019 C++ x64/x86 build tools and install then search Desktop development with C++ install it. Hope this helps.

Solution 4

If you are using Chocolatey, install the following:

choco install visualstudio2019buildtools visualstudio2019-workload-vctools

Solution 5

It is because the C++ build tools are not installed. It can be solved by installing VS 2019 C++ x64/x86 build tools in Visual Studio installer:

looks like this

Share:
66,233
Seact
Author by

Seact

Updated on July 09, 2022

Comments

  • Seact
    Seact almost 2 years

    I am trying to start about node c/c++ add-on. the node-gyp command got error

    I have installed vs2019, my command is

    node-gyp configure --msvs_version=2019
    

    the verbose output is

    gyp info it worked if it ends with ok
    gyp info using [email protected]
    gyp info using [email protected] | win32 | x64
    gyp info find Python using Python version 2.7.15 found at "C:\Users\seact\.windows-build-tools\python27\python.exe"
    gyp ERR! find VS 
    gyp ERR! find VS msvs_version was set from command line or npm config
    gyp ERR! find VS - looking for Visual Studio version 2019
    gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
    gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
    gyp ERR! find VS looking for Visual Studio 2015
    gyp ERR! find VS - found in "C:\Program Files (x86)\Microsoft Visual Studio 14.0"
    gyp ERR! find VS - could not find MSBuild in registry for this version
    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 **************************************************************
    gyp ERR! find VS
    gyp ERR! configure error
    gyp ERR! stack Error: Could not find any Visual Studio installation to use
    gyp ERR! stack     at VisualStudioFinder.fail (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
    gyp ERR! stack     at findVisualStudio2013 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:74:16)
    gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:344:14)       
    gyp ERR! stack     at findVisualStudio2015 (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:70:14)
    gyp ERR! stack     at regSearchKeys (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\find-visualstudio.js:377:20)
    gyp ERR! stack     at regGetValue (D:\Program Files\node-win-x64\node_modules\node-gyp\lib\util.js:54:7)
    gyp ERR! stack     at D:\Program Files\node-win-x64\node_modules\node-gyp\lib\util.js:33:16
    gyp ERR! stack     at ChildProcess.exithandler (child_process.js:301:5)
    gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
    gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
    gyp ERR! System Windows_NT 10.0.18362
    gyp ERR! command "D:\\Program Files\\node-win-x64\\node.exe" "D:\\Program Files\\node-win-x64\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--msvs_version=2019"
    gyp ERR! cwd D:\Projects\learn_node_ext
    gyp ERR! node -v v10.16.0
    gyp ERR! node-gyp -v v5.0.3
    gyp ERR! not ok
    
  • BReddy
    BReddy over 3 years
    This worked for me. Also, 'VS 2019 C++ x64/86 build tools' had multiple versions. I picked up the highest version number.
  • Pramesh Bajracharya
    Pramesh Bajracharya about 3 years
    2021 and npm install --g --production windows-build-tools install python 2.7? Kidding me? :/
  • DollarAkshay
    DollarAkshay over 2 years
    Just selecting Desktop development with C++ works.
  • paradite
    paradite over 2 years
    this is no longer working. official node.js installer for windows (node 16) now has the option to install build tools (python and visual studio), this is also described on top of the repo: github.com/felixrieseberg/windows-build-tools
  • Akaisteph7
    Akaisteph7 almost 2 years
    Awesome! Worked like a charm. No need to download VS.
  • Adiaos
    Adiaos almost 2 years
    Most of your code is very helpful. There is only one line of code that should be corrected. You should set VCINSTALLDIR as C:\Program Files\Microsoft Visual Studio\2022\Community\VC ( must add the "\VC" ).
  • gllambi
    gllambi almost 2 years
    This doesn't work for me and the following error happens Downloading installers failed. Error: TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor