Reputation: 821
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
Upvotes: 69
Views: 182805
Reputation: 1873
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.
Upvotes: 0
Reputation: 35
It took me a day and a half to resolve this in October 2023. On a high level, I had to perform three steps:
Now, I will explain the steps in more detail.
choco install visualstudio2019buildtools visualstudio2019-workload-vctools
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
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
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.
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!
Upvotes: 1
Reputation: 10017
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)
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
Upvotes: 62
Reputation: 83
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
Upvotes: 1
Reputation: 3997
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.
Upvotes: 2
Reputation: 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.
Upvotes: -1
Reputation: 448
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
Upvotes: 3
Reputation: 107
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)
Upvotes: -1
Reputation: 1894
TLDR: Installing the latest LTS version of Node.js via Windows Installer worked for me somehow. 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.
Upvotes: 1
Reputation: 294
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
Upvotes: 1
Reputation: 347
Same issue after upgrading to latest node LTS version. This did the trick for me:
npm install
Upvotes: 0
Reputation: 1206
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
Upvotes: 2
Reputation: 821
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:
Upvotes: 9
Reputation: 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
Upvotes: -1
Reputation: 633
You do not have to install Visual Studio, just install the windows build tools:
npm install --g --production windows-build-tools
This should fix that.
Upvotes: 60
Reputation: 95
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
Upvotes: 5
Reputation: 1841
Instead of running 'npm install'
, run 'npm update'
directly in the folder. This solved my issue.
Upvotes: 1
Reputation: 31
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.
Upvotes: 0
Reputation: 157
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.
Upvotes: -2
Reputation: 390
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
Upvotes: 2
Reputation: 3811
If you are using Chocolatey, install the following:
choco install visualstudio2019buildtools visualstudio2019-workload-vctools
Upvotes: 15
Reputation: 95
Your powershell is running probably in constrained mode. See this thread: how to change PowerShell mode to fulllanguage mode from constrained mode?
Upvotes: 4
Reputation: 9
and it should solve the issue.
Upvotes: 0
Reputation: 615
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.
Upvotes: 20