node-gyp: how to fix `VS VCINSTALLDIR not set, not running in VS Command Prompt` using vs2022 ,help me please.
Please look thru your error log for the string gyp info using node-gyp@
and if the version number is less than the current release of node-gyp then please upgrade using the instructions at https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md and try your command again.
Requests for help with node-sass
are very common. Please be aware that this package is deprecated, you should seek alternatives and avoid opening new issues about it here.
- Node Version: 8.1.3
- Platform: Windows
- Compiler: VS2022 windows
- Module:
$ npm install
npm WARN deprecated vscode@1.1.37: This package is deprecated in favor of @types/vscode and vscode-test. For more information please read: https://code.visualstudio.com/updates/v1_36#_splitting-vscode-package-into-typesvscode-and-vscodetest
npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! code 1
npm ERR! path D:\heart\Git\MyVSCode\vs-shell-format\node_modules\keytar
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.9.7 found at "D:\Program Files\Python39\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version was set from command line or npm config
npm ERR! gyp ERR! find VS - looking for Visual Studio version 2022
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 "D:\Program Files\Microsoft Visual Studio\2022\Community"
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
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
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
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack at VisualStudioFinder.fail (C:\Users\heart\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack at C:\Users\heart\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\heart\AppData\Roaming\npm\node_modules\npm\node_modules\nodnpm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! System Windows_NT 10.0.22499
npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "C:\\Users\\heart\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\heart\Git\MyVSCode\vs-shell-format\node_modules\keytar
npm ERR! gyp ERR! node -v v16.13.0
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\heart\AppData\Local\npm-cache\_logs\2021-11-17T13_51_11_770Z-debug.log
$ npm --verbose
npm verb cli [
npm verb cli 'D:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Users\\heart\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli '--verbose'
npm verb cli ]
npm info using npm@8.1.3
npm info using node@v16.13.0
npm timing npm:load:whichnode Completed in 0ms
npm timing config:load:defaults Completed in 1ms
npm timing config:load:file:C:\Users\heart\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 2ms
npm timing config:load:builtin Completed in 2ms
npm timing config:load:cli Completed in 2ms
npm timing config:load:env Completed in 0ms
npm timing config:load:project Completed in 1ms
npm timing config:load:file:C:\Users\heart\.npmrc Completed in 0ms
npm timing config:load:user Completed in 0ms
npm timing config:load:file:C:\Users\heart\AppData\Roaming\npm\etc\npmrc Completed in 0ms
npm timing config:load:global Completed in 1ms
npm timing config:load:validate Completed in 1ms
npm timing config:load:credentials Completed in 0ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 9ms
npm timing npm:load:configload Completed in 9ms
npm timing npm:load:setTitle Completed in 0ms
npm timing npm:load:setupLog Completed in 1ms
npm timing config:load:flatten Completed in 1ms
npm timing npm:load:cleanupLog Completed in 2ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load:projectScope Completed in 0ms
npm timing npm:load Completed in 22ms
npm <command>
Usage:
npm install install all the dependencies in your project
npm install <foo> add the <foo> dependency to your project
npm test run this project's tests
npm run <foo> run the script named <foo>
npm <command> -h quick help on <command>
npm -l display usage info for all commands
npm help <term> search for help on <term> (in a browser)
npm help npm more involved overview (in a browser)
All commands:
access, adduser, audit, bin, bugs, cache, ci, completion,
config, dedupe, deprecate, diff, dist-tag, docs, doctor,
edit, exec, explain, explore, find-dupes, fund, get, help,
hook, init, install, install-ci-test, install-test, link,
ll, login, logout, ls, org, outdated, owner, pack, ping,
pkg, prefix, profile, prune, publish, rebuild, repo,
restart, root, run-script, search, set, set-script,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
Specify configs in the ini-formatted file:
C:\Users\heart\.npmrc
or on the command line via: npm <command> --key=value
More configuration info: npm help config
Configuration fields: npm help 7 config
npm@8.1.3 C:\Users\heart\AppData\Roaming\npm\node_modules\npm
npm verb exit 0
npm timing npm Completed in 187ms
npm verb code 1
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 50 (19 by maintainers)
Commits related to this issue
- :construction_worker: :hammer: ci: try node 16 to fix gyp windows issue https://github.com/nodejs/node-gyp/issues/2552 Signed-off-by: kWeiZh <kweizh@gmail.com> — committed to zwpaper/tree-sitter-beancount by zwpaper 2 years ago
- Just build windows with new node-gyp https://github.com/nodejs/node-gyp/issues/2552 — committed to Soulmate-Lights/soulmate-ide by elliottkember 2 years ago
Please upgrade to 8.4. https://github.com/nodejs/node-gyp/releases
I have VS 2022 and node-gyp8.4 I still see error
Try running
npm config set msvs_version 2022
before your other commands.https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md
Probably because of the “constrained language mode” of powershell.
node-gyp use a piece of c# code to obtained the information of visual studio:
On my machine, the corresponding javascript file is
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js
, which invokesC:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\Find-VisualStudio.cs
;However, PowerShell has a “ConstrainedLanguage” mode which prevent evaluation of c# code. See: ConstrainedLanguag, and node-gyp does not print useful information about this…
To workaroud this, try to set the system
__PSLockdownPolicy
environment variable to 8 and re-launch your cmd or powershell.@mrudulp Follow the Guide. Is it fixed。
seem that I had updated node-gyp to 8.4.0. but when I exec eval
npm install
they are still using v8.3.0issue still exists…
@xXAvoraXx I finally resolved this after editing
find-visualstudio.js
to log more information.TL;DR - If you’re getting
gyp ERR! find VS - does not match this Visual Studio Command Prompt
Try adding another directory to the end of yourVCINSTALLDIR
path. For example:C:\Program Files\Microsoft Visual Studio\2022\Community\VC
C:\Program Files\Microsoft Visual Studio\2022\Community
It shouldn’t matter what the final directory is provided it exists.
Long answer:
The issue lies on https://github.com/nodejs/node-gyp/blob/0f1f667b737d21905e283df100a2cb639993562a/lib/find-visualstudio.js#L55
That resolves
envVcInstallDir
to the parent folder of yourVCINSTALLDIR
environment variable.In my case, I had my env variable set to
C:\Program Files\Microsoft Visual Studio\2022\Community
, which is then resolved asC:\Program Files\Microsoft Visual Studio\2022
.This led to a mismatch in the check below since obviously the two paths are not equal: https://github.com/nodejs/node-gyp/blob/0f1f667b737d21905e283df100a2cb639993562a/lib/find-visualstudio.js#L449
Documentation can be improved via pull requests. I do not use Windows so I cannot propose the correct changes.
Cool. In cmd, type
SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\
like they do in https://stackoverflow.com/questions/1679560/using-visual-studio-command-prompt-tools-everywhereHI @cclauss, Can you verify
; “builtin” config from C:\Program Files\nodejs\node_modules\npm\npmrc
prefix = “C:\Users\manju\AppData\Roaming\npm”
; “global” config from C:\Users\manju\AppData\Roaming\npm\etc\npmrc
; msvs_version = “2017” ; overridden by user
; “user” config from C:\Users\manju.npmrc
and = “yarn” C:\Program Files\Microsoft Visual Studio\2017\Community\Msbuild\Current\Bin\MSBuild.exe = “” config = “msvs_version” Files\Microsoft = “Visual” msbuild_path = “C:\Program Files\Microsoft Visual Studio\2017\Community\Msbuild\Current\Bin\MSBuild.exe” msvs_version = “2017” node_gyp = “C:\Users\manju\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js” python = “c:\Python\27\python.exe” python3.10 = “” registry = “https://registry.npmjs.org/” Studio\2017\Community\Msbuild\Current\Bin\MSBuild.exe = “”
; node bin location = C:\Program Files\nodejs\node.exe ; cwd = C:\WINDOWS\system32 ; HOME = C:\Users\manju ; Run
npm config ls -l
to show all defaults.In
cmd
, did you donpm config set msvs_version 2022
?@heartacker The log output above says:
which is the current release so no further upgrade is needed.
Is there a
VCINSTALLDIR
value printed when you run theSET
command (without parameters) at Visual Studio command prompt?