node-gyp `msvs_version` is not a valid npm option

11k Views Asked by At

I'm currently trying to develop a Node application that can call C++ functions. I came across people saying that we have to use the node-gyp package. Upon following this setup, when I try to npm config set msvs_version 2017 in my cmd, it gives me the following error.

npm ERR! msvs_version is not a valid npm option

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Local\npm-cache_logs\2023-03-06T05_02_04_115Z-debug-0.log

I have Visual Studio 2022 installed and Python 3.10 installed. I've tried to use different commands such as:

npm config set msvs_version 2022 -g
npm config set msvs_version=2022

I've also tried to reinstall the C++ development workloads in Visual Studio but no luck with all of them. I can't seem to find any information on Google. Any help is appreciated! Thanks in advance.

Log file:

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 2ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 2ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 1ms
9 timing config:load:project Completed in 2ms
10 timing config:load:file:C:\Users\user\.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:C:\Users\user\AppData\Roaming\npm\etc\npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:setEnvs Completed in 1ms
15 timing config:load Completed in 12ms
16 timing npm:load:configload Completed in 13ms
17 timing npm:load:mkdirpcache Completed in 1ms
18 timing npm:load:mkdirplogs Completed in 1ms
19 verbose title npm config set msvs_version 2017
20 verbose argv "config" "set" "msvs_version" "2017"
21 timing npm:load:setTitle Completed in 2ms
22 timing config:load:flatten Completed in 3ms
23 timing npm:load:display Completed in 4ms
24 verbose logfile logs-max:10 dir:C:\Users\user\AppData\Local\npm-cache\_logs\2023-03-06T05_02_04_115Z-
25 verbose logfile C:\Users\user\AppData\Local\npm-cache\_logs\2023-03-06T05_02_04_115Z-debug-0.log
26 timing npm:load:logFile Completed in 7ms
27 timing npm:load:timers Completed in 0ms
28 timing npm:load:configScope Completed in 0ms
29 timing npm:load Completed in 30ms
30 info config set "msvs_version" "2017"
31 timing command:config Completed in 2ms
32 verbose stack Error: `msvs_version` is not a valid npm option
32 verbose stack     at Config.set (C:\Program Files\nodejs\node_modules\npm\lib\commands\config.js:158:15)
32 verbose stack     at Config.exec (C:\Program Files\nodejs\node_modules\npm\lib\commands\config.js:120:22)
32 verbose stack     at Config.cmdExec (C:\Program Files\nodejs\node_modules\npm\lib\base-command.js:130:17)
32 verbose stack     at Npm.exec (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:154:20)
32 verbose stack     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli.js:134:5)
33 verbose cwd C:\Users\user
34 verbose Windows_NT 10.0.22621
35 verbose node v18.14.2
36 verbose npm  v9.5.0
37 error `msvs_version` is not a valid npm option
38 verbose exit 1
39 timing npm Completed in 52ms
40 verbose code 1
41 error A complete log of this run can be found in:
41 error     C:\Users\user\AppData\Local\npm-cache\_logs\2023-03-06T05_02_04_115Z-debug-0.log
2

There are 2 best solutions below

0
On

Edit npm Configuration Manually: If directly setting the msvs_version through npm commands doesn't work, you can manually edit the npm configuration file. Run npm config edit in your terminal, which opens the configuration file in your default text editor. Then, add the line msvs_version=2022 to the file and save it

2
On

Using npm config set msvs_version {version} errored for me as well.

However, using npm config edit then adding msvs_version={version} in the file directly worked fine.

I confirmed that it was picked up by npm. Give that a shot