17

The problem that I am having is that I cant install the packages for a project, it keeps erroring with:

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

I have tried to follow advice from these threads that other people had:

How to fix node.js error like "gyp ERR! find VS including the "Desktop development with C++" workload." when I launch Nuxt.js project

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

But neither seemed to help.

What I have done so far:

  • I installed the latest VS Code (2022 Community) with Desktop development with C++ along with MSVC v143 - VS 2022 C++ x64/x86 build tools

  • I have configured msvs_version to have the value of 2022, I did that with npm config set msvs_version=2022 and with node-gyp configure --msvs_version=2022

  • I have tried installing windows build tools npm install --global --production windows-build-tools but it just says that ...Node.js now incldues build tools for Windows...

  • I have also manually built the node-gyp using the commands found in the second post I listed above node-gyp configure node-gyp configure --msvs_version=2022 node-gyp build and its all greens and oks

And I have no idea what else I can do

1
  • I'm running npm install and getting this error. I don't have C++ and I don't want it that I know of. My project is nodejs project in vscode. Why am I getting this error? Commented Mar 21 at 2:37

4 Answers 4

11

I found the problem after hours of searching, it was my node version, i was at 16.x.x, I installed node version manager and moved to version 14 and it worked.

4
  • Thanks. It works for me too. I think Node.js 16 Windows installer have a bug🤔 Commented Feb 4, 2022 at 9:33
  • 5
    Problem still persists with node 18
    – Nicoara
    Commented Nov 17, 2022 at 17:50
  • My machine having node version 14.19.0, and still facing the issue.
    – Rashid
    Commented Aug 21, 2023 at 7:38
  • Solved it by downgrading nodejs is probably not the best answer.
    – flayman
    Commented Oct 25, 2023 at 11:09
10

Solved node-gyp in Windows 11, VSCode, Visual Studio 2022

node -v
v18.4.0

nvm version
1.1.9

node-gyp -v
v9.0.0



node-gyp configure --msvs_version=2022

enter image description here

Start Visual Studio Installer

enter image description here

Beside Visual Studio Community 2022 -> Modify ->Individual Components Type Visual C++

enter image description here

Make sure MSVC v143 ... x64/x86 build tools (Latest) is checked.

Check current Windows version

enter image description here

enter image description here

Back to Visual Studio install, type SDK, and find the correct SDK version. for me, Windows 11 SDK (10.0.22000.0)

enter image description here

After all those setup.. I still get

gyp ERR!  find VS - does not match this Visual Studio Command Prompt

knowing that I have to hack the code

adding this 3 lines above the error log

    +this.addLog("this.envVcInstallDir: " + this.envVcInstallDir)
    +this.addLog("vsPath: " + vsPath)
    +this.addLog("path.relative(this.envVcInstallDir, vsPath): " + path.relative(this.envVcInstallDir, vsPath))
    if (this.envVcInstallDir &&
      path.relative(this.envVcInstallDir, vsPath) !== '') {
      this.addLog('- does not match this Visual Studio Command Prompt')
      return false
    }

and tracing into

    if (process.env.VCINSTALLDIR) {
      this.envVcInstallDir =
        path.resolve(process.env.VCINSTALLDIR, '..')
      this.addLog('running in VS Command Prompt, installation path is:\n' +
        `"${this.envVcInstallDir}"\n- will only use this version`)
    } else {
      this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
    }

enter image description here

Finally, have to add something at the end of VCINSTALLDIR

Problem solved, will uninstall VS 2017 & 2019 to save space.

2
  • 1
    This answer is very thorough and it worked for me, substituting Windows 10.
    – flayman
    Commented Oct 25, 2023 at 11:10
  • 1
    such a great idea to log-debug gyp! thanks! in my case I needed to change VCINSTALLDIR value Commented Mar 20 at 12:01
2

Not sure which one (or combination) of the steps that i took solved the issue, but they were:

  1. Updated to latest node.js version (v18.12.1 as of writing this) and ran chocolatey ("install additional packages" checkbox) through the installer, it updated python to 3.11.
  2. Removed all visual studio build installs, except for 2017.
  3. Ran command npm config set msvs_version=2017.
  4. Restarted my machine.
  5. Ran the nodejs repair option of the installer.

And that's it!

For context, I was updating an Angular project 14 -> 15 and started running into these issues.

Along the way I've also installed Visual Studio 2022 Community with the Development with c++ workload, but node-gyp was still not recognizing it.

Also had Visual Studio Build Tools 2019 that i've uninstalled.

The 2017 version I'm running is 15.9.43.

Hope this helps someone in the future :)

1
  • Reran the nodejs installer, ran npm install again and no errors. I don't have Visual Studio only vscode, it's a nodejs project. I don't know why I was getting the error when running npm install in my nodejs project but repair seems to work now. The installer mentioned something about installing chocolate (Visual C++) tools during install initially so maybe it failed to install the first time and worked on the repair. Commented Mar 21 at 2:42
1

I solved by the below steps:

After installed the Visual Studio 2019 Community with the Development with C++

I still see the error msvs_version does not match this version on my npm install log

So I run npm config get msvs_version to check the current msvs_version

Then I set it to match with my install Visual Studio version

npm config set msvs_version 2019 --global

Image of Got Error

Image of Fixed the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.