1

I'm trying to run Node C++ Addon example from https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/node-addon-api

With commands:

npm install
node ./

I'm using Windows 10 with node.js v12.18.3 node-gyp v7.1.0

Have the following Variables User variables:

Path:
...
C:\Users\User\.windows-build-tools\python27\

System Variables:

VCINSTALLDIR
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC

VS150COMNTOOLS (is this name correct, is this variable is relevant?)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools

msvs_version
2017

Npm configuration details (npm config list --json):

"msvs_version": "2017"
"msbuild_path": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\MSBuild.exe"
"node_gyp": "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js",
"python": "C:\\Users\\User\\.windows-build-tools\\python27\\python.exe",

I've installed Visual Studio 2017 with all the relevant C++ build tools as mentioned here: How can I solve error gypgyp ERR!ERR! find VSfind VS msvs_version not set from command line or npm config?

But still receive this error:

gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2017
gyp ERR! find VS running in VS Command Prompt, installation path is:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"
gyp ERR! find VS - will only use this version
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 - MSBuild in "C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe"
gyp ERR! find VS - msvs_version does not match this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS msvs_version does not match this VS Command Prompt or the
gyp ERR! find VS installation cannot be used.
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 (C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:391:20
gyp ERR! stack     at C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:42:7
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:7)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Projects\VS\Electron\node-addon-examples-master\1_hello_world\node-addon-api
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello_world@0.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello_world@0.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

When I try change all the parameters above to use VS2015 with all the VS2015 build tools installed it works correctly.

How can I fix the errors above to use Visual Studio 2017 or 2019?

gscriptor
  • 93
  • 3
  • 11

2 Answers2

2

Try setting this environment in the command window where you are firing the build, it is to map VS2017 to 15.

SET VS140COMNTOOLS=%VS150COMNTOOLS%
Satyan
  • 1,346
  • 8
  • 15
1

From the logs, i want to believe you are experiencing version conflicts between node-gyp and VS Build Tools.

Your node.js v12.18.3 and node-gyp v7.1.0 looks ok.

I also observed from practice that node-gyp v7.1.0 works best with VS2019 Build Tools.

Just Making sure your node-gyp is installed globally

$ npm install -g node-gyp

and you also have Python Installed, at least one of v2.7, v3.5, v3.6, v3.7, or v3.8.

If you have multiple Python versions installed, you can identify which Python version node-gyp should use by setting your npm config using this command:

$ npm config set python /path/to/executable/python

If you don't have VS2019 Build Tools installed yet, I would also advice you Visit the Microsoft's Download Page directly to get the VS2019 Build Tool Downloaded and Installed, this was recently updated.

Assuming you have VS2019 Build Tools and other Versions of Build Tools installed already i.e VS2017, VS2015. I recommend opening the Visual Studio Uninstaller, i would advice uninstalling all other versions of VS Build Tools except VS2019 Build Tools which should be compatible with the latest version of your Globally Installed node-gyp package.

Update your VS2019 Build Tools, a new update was currently rolled out.

Also Make sure to add "<!@(node -p "require('node-addon-api').include")" to your "include_dirs" in your bindings.gyp config file.

{
...,
 "include_dirs": [
    "<!@(node -p \"require('node-addon-api').include\")"
 ],
...
}

I hope this helps at least!

masdren
  • 27
  • 3