How to force npm to use different node-gyp version when installing packages?
Asked Answered
P

7

13

I am running Node 16.13.2 LTS with Visual Studio 2022. During the installation of a package, node-gyp is triggered and fails.

npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node build.js || nodejs build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.9.4 found at "C:\Users\ahboy\AppData\Local\Programs\Python\Python39\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Professional"
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found

error

I went to do some research and found out that [email protected] does not support VS 2022. Only version [email protected] does. So I started to try to get npm to use [email protected] but nothing works including this advice from node-gyp github page to install node-gyp globally and point the path in npmrc file.

So what can be done to force npm to use different node-gyp versions when installing packages?

Prejudice answered 21/1, 2022 at 11:57 Comment(3)
Its a bad solution but most packages I've use that use node-gyp are much more stable and easy to install on linux rather than windows. I usually use the vscode node docker devcontainer and that works great - if you don't NEED to run on windows.Authorized
Have you seen or tried the instructions from github.com/nodejs/node-gyp/blob/master/docs/…?Obovate
Tried that already but somehow the version that node-gyp reports is still 8.3.0Prejudice
N
5

Declare your dependency on the newer version of node-gyp in your package.json file. Add this to your dependency block:

 "node-gyp"              : "^8.4.1",

I did exactly this about an hour ago to get our github actions CI tests working since the switch of 'windows-latest' became windows server 2022.

Newmodel answered 1/4, 2022 at 4:35 Comment(0)
F
0

If you installed latest node-gyp.

Check the version of node-gyp both in terminal (Powershell) and vscode terminal. One of them should be pointing to the 8.4 and another one to 8.3 So the terminal that you are running the app, looks like is not recognizing the path of 8.4 version.

Fike answered 25/1, 2022 at 2:39 Comment(0)
M
0

What does the package.json in the package your installing show for the node-gyp dependency version? Also look at all subdependencies of those dependencies to see if any of those reference version 8.3. I've ran into this same issue as well on windows. If you can't get your version to update, you can also install visual studio build tools 2017 and set your msvs_version to 2017 and it should pick that up for you. No need to install the full vs2017, just the build tools will do fine.

Mcclintock answered 30/1, 2022 at 23:57 Comment(0)
P
0

I had a similar issue, what solved it for me was using nvm: Node Version Manager to install Node version 14, alongside the latest one. The repository I was cloning had a lot of dependencies. Also, I did not need to be on the bleeding edge of progress with the latest Node version.

Here is further resource on how to install and use nvm: Installing nvm on Windows.

Plasticine answered 19/5, 2022 at 14:16 Comment(3)
nvm is extremely old. For Mac you should use n and for Windows voltaPracticed
nvm is old but it worksSonjasonnet
@Practiced Volta solved my problem. Much simplier than nvm. Spend a lot of time before. Thanks!Empressement
P
0

Updating the node-gyp globally didn't resolve this issue for me. What did was updating it internally - the one bundled with node. To do that following the instructions here:

https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md

Preempt answered 16/8, 2023 at 7:27 Comment(0)
L
0

i delete my node-gyp folder automatically installed by nvm in

D:\nvm{version}\node_modules\npm\node_modules\node-gyp,

and use this:

npm uninstall -g node-gyp@{version}

or default: npm uninstall -g node-gyp

and i successfully use my installed node-gyp version.

Leitao answered 13/4, 2024 at 5:22 Comment(0)
L
0

What have solved similar issue on my end:

Update node-gyp

npm install --global node-gyp

Clean npm cache

npm cache clean --force

Then install npm/yarn/whatever again

npm intall
Legist answered 12/7, 2024 at 23:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.