我正在尝试从https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/node-addon-api
带命令:
npm install
node ./
我正在使用Windows 10node.js v12.18.3节点gyp v7.1.0
具有以下变量用户变量:
Path:
...
C:UsersUser.windows-build-toolspython27
系统变量:
VCINSTALLDIR
C:Program Files (x86)Microsoft Visual Studio2017ProfessionalVC
VS150COMNTOOLS (is this name correct, is this variable is relevant?)
C:Program Files (x86)Microsoft Visual Studio2017ProfessionalCommon7Tools
msvs_version
2017
Npm配置详细信息(Npm配置列表--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",
我已经安装了Visual Studio 2017以及这里提到的所有相关C++构建工具:如何解决错误吉普赛人ERR!呃!是否从命令行或npm配置中找到未设置的VSfind VS msvs_version?
但是仍然收到这个错误:
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 Studio2017Professional"
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)MSBuild14.0binMSBuild.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:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibfind-visualstudio.js:121:47)
gyp ERR! stack at C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibfind-visualstudio.js:74:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibfind-visualstudio.js:351:14)
gyp ERR! stack at C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibfind-visualstudio.js:70:14
gyp ERR! stack at C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibfind-visualstudio.js:391:20
gyp ERR! stack at C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibutil.js:54:7
gyp ERR! stack at C:UsersUserAppDataRoamingnpmnode_modulesnode-gyplibutil.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:ProjectsVSElectronnode-addon-examples-master1_hello_worldnode-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.
当我尝试更改上面的所有参数以在安装了所有VS2015构建工具的情况下使用VS2015时,它可以正常工作。
如何修复以上错误以使用Visual Studio 2017或2019?
尝试在启动构建的命令窗口中设置此环境,即将VS2017映射到15。
SET VS140COMNTOOLS=%VS150COMNTOOLS%
从日志中,我想相信您在node-gyp和VS构建工具之间遇到了版本冲突。
您的node.js v12.18.3和node-gyp v7.1.0看起来不错。
我还从实践中观察到,node gyp v7.1.0与VS2019构建工具配合使用效果最好。
只需确保您的节点gyp已在全球范围内安装
$ npm install -g node-gyp
并且您还安装了Python,至少是v2.7、v3.5、v3.6、v3.7或v3.8中的一个。
如果您安装了多个Python版本,您可以通过使用以下命令设置npm配置来确定gyp应该使用哪个Python版本节点:
$ npm config set python /path/to/executable/python
如果您还没有安装VS2019 Build Tools,我还建议您直接访问Microsoft的下载页面,下载并安装VS2019构建工具,这是最近更新的。
假设您已经安装了VS2019构建工具和其他版本的构建工具,即VS2017、VS2015。我建议打开Visual Studio卸载程序,我建议卸载除VS2019生成工具之外的所有其他版本的VS生成工具,该工具应与您的全局安装节点gyp包的最新版本兼容。
更新您的VS2019 Build Tools,当前已推出新的更新。
还要确保添加"<(node-p"require(‘node-addon-api’(.include"("到您的";include_dirs"在bindings.gyp配置文件中。
{
...,
"include_dirs": [
"<!@(node -p "require('node-addon-api').include")"
],
...
}
我希望这至少能有所帮助!