node-gyp configure got "gyp ERR! find VS"
Asked Answered
E

25

69

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
Enolaenormity answered 18/8, 2019 at 3:19 Comment(1)
In my case, Downgrading the node version from 18 to 16 resolved the problem!Rainey
W
61

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\Microsoft Visual Studio\2022\Community\VC

Also, additionally add user environment variable GYP_MSVS_VERSION= 2022 (see this answer)

VCINSTALLDIR

Before npm install delete node_modules folder from your root folder along with package-lock.json and then re ran npm install.

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

Willena answered 21/1, 2022 at 10:2 Comment(7)
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" ).Regenerative
Thanks @Regenerative for suggesting edits and Robin for copying it.Willena
Does the python setting have to be global as well?Chuff
@Chuff yes if you open Terminal on windows and type python --version it should printWillena
This is very close, but I had to add one last piece - GYP_MSVS_VERSION. see my answer belowAngelangela
Brilliant! Last line saved me thanksLapp
I have NodeJS version 20 installed and I'm getting the error: "npm ERR! msbuild_path is not a valid npm option" while running your line.Nace
E
58

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://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/31D1U.png

Eliason answered 8/8, 2020 at 3:2 Comment(4)
2021 and npm install --g --production windows-build-tools install python 2.7? Kidding me? :/Katzman
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-toolsSixtyfour
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 descriptorGinglymus
This did not work for meLighthearted
N
18

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.

Nourish answered 30/1, 2020 at 10:7 Comment(2)
This worked for me. Also, 'VS 2019 C++ x64/86 build tools' had multiple versions. I picked up the highest version number.Lengel
I picked latest version of VS 2022 C++ x64/86 build toolsTweeddale
D
14

If you are using Chocolatey, install the following:

choco install visualstudio2019buildtools visualstudio2019-workload-vctools
Denominational answered 26/2, 2021 at 13:16 Comment(1)
Awesome! Worked like a charm. No need to download VS.Crone
E
8

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

Enolaenormity answered 18/8, 2019 at 3:53 Comment(0)
R
5

Downloading the latest Visual Studio build Tools

https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

and running the following command in the 'Program Files (x86)\Microsoft Visual Studio\2017\BuildTools' Directory

npm install --g --production windows-build-tools

and Installing node-gyp in the current directory

npm install node-gyp

Worked For me on Windows 10

for more, please visite the official node-gyp installation guide

Rosary answered 22/6, 2021 at 12:23 Comment(0)
V
4

Your powershell is running probably in constrained mode. See this thread: how to change PowerShell mode to fulllanguage mode from constrained mode?

Vociferance answered 31/7, 2020 at 1:49 Comment(0)
A
3

Solution that worked for me was to install latest Visual Studio Build Tools and then execute following command, taken from node-gyp installation instructions here:

npm config set msvs_version 2017

Anette answered 31/8, 2022 at 22:5 Comment(1)
latest node version does not accept setting it in cmd. Use npm config edit instead and write msvs_version 2017Medea
R
2

I had to set python path for npm even though I had python on my PATH.

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

then try npm install again

Refuse answered 20/3, 2021 at 23:11 Comment(0)
C
2

It should be a npm package bug of windows-build-tools.

Step 1: Be sure you installed Visual Studio Code

Step 2: Search %temp% under window search bar (Copy %temp% then press windows button + Ctrl V)

Step 3: Create 'dd_client_.log.txt' and enter 'Closing installer. Return code: 3010.'

Now you should be able to finish the whole process with npm install --global windows-build-tools

Continuo answered 17/12, 2021 at 2:11 Comment(0)
A
2

My working environment: Visual Studio Enterprise 2022, Python 3.11, and Node v18.13.0. I did everything according to steel's answer, but still got errors. Looks like npm config set msvs_version 2022 --global doesn't help.

I finally got it working by adding an Environment Variable - GYP_MSVS_VERSION and setting it to 2022.

enter image description here

Angelangela answered 2/2, 2023 at 3:1 Comment(0)
N
1

Instead of running 'npm install', run 'npm update' directly in the folder. This solved my issue.

Nickelsen answered 12/6, 2021 at 0:25 Comment(0)
J
1

Same issue faced by me with VS 2022 community edition, node 15.x, python 3.10

npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows

Issue was due to non-compatible Node version 15.x.x to gyp and, successfully resolved with downgrading node to 14.17.3 version.

Thanks

Juline answered 4/5, 2022 at 14:40 Comment(0)
A
1

TLDR: Installing the latest LTS version of Node.js via Windows Installer worked for me somehow. Latest LTS Version

Nodejs Latest LTS Version

I tried all the answers from this thread and some other articles as well but nothing was working for me. After spending 6+ hours on this issue, I saw this note on Windows-Build-Tools Github page.

Please note that the official Node.js for Windows installer can now automatically install the required tools. That's likely a much better option than the module listed here (windows-build-tools).

So I installed the latest LTS version of Node.js via Windows Installer from Node js website as shown in the above image and it worked somehow.

Asquith answered 21/5, 2022 at 1:54 Comment(0)
S
1

I faced a similar issue. After quickly scanning the logs, I could see that the error code was 1. Error code 1 (in npm) usually occurs because of version mismatch between modules/packages.

When I run the command npm update --legacy-peer-deps the problem was resolved.

Most probably a particular package is causing the issue, so although the error raised by node-gyp might appear to be confusing, when actually it may happen because of incompatibility due to updated node or some other major package version with some other package. So, do try to add --legacy-peer-deps flag with the npm update

Shope answered 29/5, 2023 at 11:9 Comment(0)
T
1

It took me a day and a half to resolve this in October 2023. On a high level, I had to perform three steps:

  1. Install Visual Studio 2019 build-tools through Chocolatey (although I am using Visual Studio 2022)
  2. Update the configuration through yarn package manager
  3. Downgrade NodeJS to match the version supported by node-sass

Now, I will explain the steps in more detail.

1st Step - Build tools 2019

choco install visualstudio2019buildtools visualstudio2019-workload-vctools

2nd Step - Yarn configurations

Set the correct path to you Python executable:

yarn config set python C:\Python310\python.exe

Set the msvs_version:

yarn config set msvs_version 2019 --global

Set msbuild_path:

yarn config set msbuild_path "C:\Program Files\Microsoft Visual Studio\2019\Community\Msbuild\Current\Bin\MSBuild.exe"

Your VCINSTALLDIR ENV variable should be set to C:\Program Files\Microsoft Visual Studio\2019\Community\VC

Add user Environment variable GYP_MSVS_VERSION= 2019

enter image description here

Additionally, you might want to upgrade node-gyp, but it wasn't the problem in my case:

cd "C:\Program Files\nodejs"
cd node_modules\npm\node_modules\@npmcli\run-script
npm install node-gyp@latest

Delete the node_modules folder from your project folder, and then run yarn install

3rd Step - Downgrading NodeJS

From the beginning, the error was pointing to the node-sass package I was using without specifying the issue. Turned out it was a version incompatibility.

enter image description here

Source: https://www.npmjs.com/package/node-sass?activeTab=readme

In my case, I simply deleted the latest NodeJS package and installed a new particular version that was compatible with my version of node-sass.

choco uninstall nodejs@latest
choco install nodejs-18.0.0

If you're using npm, just change the word yarn to npm in all the commands. Hope it helps!

Touchdown answered 3/11, 2023 at 22:29 Comment(0)
W
0
  1. Download Visual Studio Community Edition
  2. Run the executable
  3. Choose the options as below.

enter image description here

and it should solve the issue.

Wodge answered 11/5, 2020 at 1:46 Comment(1)
Just selecting Desktop development with C++ works.Dentistry
D
0

In case if someone still has the visual studio installation required error after going through all the steps mentioned above. I had this issue when I was trying to run an electron application. The solution for my issue was simply adding the visual studio to the environment variables after going through all the above steps.

To set the path run the following command on cmd (if possible as admin):

setx VCTargetsPath “C:\Program Files (x86)\MSBuild\15.0"

Note: the path for my visual studio was as in the above. you may have to change it according to your installation.

The software versions I was using are as follows: nodejs : 14.17.0 OS : windows10 64-bit Python : 2.7.15 (installed default with node js) Visual studio : community edition 2019

some of the other things to check is to make sure the python version, msvs_version are set to the correct versions in the npm config.

Daddylonglegs answered 25/5, 2021 at 15:22 Comment(0)
M
0

Same issue after upgrading to latest node LTS version. This did the trick for me:

  1. removed node_modules folder
  2. removed package-lock.json file
  3. npm install
Maudmaude answered 8/4, 2022 at 11:49 Comment(0)
N
0

For me I had to install VS 2017 Build Tools (in addition to VS 2022 Build Tools) - but for 2017 build tools I ONLY needed the "Visual C++ build tools" (with VC++ 2017 and Visual C++ 2017 Build Tools core features and Redistributable Update)

Now VS 2022 does not seem to have the "Visual C++ Build Tools", although it does have "Desktop development with C++". 3 Days of my life gone.

Norenenorfleet answered 18/12, 2023 at 18:45 Comment(0)
C
-1

on my computer works with the next commands

npm install --g --production windows-build-tools
npm install node-gyp
npm audit fix
npm install node-phpass
Cohobate answered 5/11, 2021 at 13:45 Comment(0)
N
-1

I had the same problem before, thanks C. Szabo's answer.

node-gyp use Powershell script to find Visual Studio. You should check

$ExecutionContext.SessionState.LanguageMode

in Powershell. If it return 'ConstrainedLanguage', node-gyp will fail to find Visual Studio. Change _PSLockdownPolicy in register can fix this problem, see this answer. (Don't forget to reboot Windows)

Nub answered 28/6, 2022 at 6:14 Comment(0)
D
-1

I also encountered this error. After trying all the suggestions I could find and spending 2 days trying to resolve it, I finally found out the reason it wasn't working for me was that in my build environment I didn't have ProgramData env variable defined. After adding "ProgramData": "C:\ProgramData" everything started working like a charm.

When this env var is not defined, for whatever reason, query2.EnumAllInstances() in Find-VisualStudio.cs returns empty enumeration.

Hopefully this will be useful for someone as well.

Deciare answered 8/9, 2022 at 9:9 Comment(0)
R
-1

npm install --g --production windows-build-tools

Reider answered 24/11, 2022 at 12:25 Comment(0)
A
-2

My friend creates the project and her node/npm versions are not compatible with mine. So I try to upgrade my npm versions only. It's solved the problem.

But some of the dependencies are not working. So I update the node versions, as along with the npm version, will update. It solved almost all problems and errors.

You should find the correct compatible version of node and npm. Here you can find the node version and compatible npm version.

Make sure to check your npm version and node versions are compatible.

Ammonite answered 7/5, 2021 at 2:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.