首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >nodejs/电子锻造/ not :在尝试了我可以在网上找到的所有技巧之后,找不到任何Visual安装来使用

nodejs/电子锻造/ not :在尝试了我可以在网上找到的所有技巧之后,找不到任何Visual安装来使用
EN

Stack Overflow用户
提问于 2020-08-28 05:01:29
回答 2查看 10.2K关注 0票数 1

引言

在查阅了数以百万计的在线提示之后,包括

本“综合指南”,它引入了与官方文档相反的想法

我仍然无法安装某些第三方软件包,需要在npm或纱线上进行本地安装。我也没有收到来自nodejsnode-gyp github发布论坛的任何回复。

我即将发布一款已经在macOS上很好地使用macOS构建的应用程序,但它无法在Windows上运行。

主要问题是构建第三方包的npm依赖项之一node-gyp无法在我的机器上找到Visual。我使用VS2017社区并安装了node-gyp所需的所有组件。

我的圈套

  • 节点版本node -v=v12.18.3和npm -v=6.14.8
  • Platformsysteminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type" (Windows)
代码语言:javascript
运行
复制
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18362 N/A Build 18362
System Type:               x64-based PC
  • 编译器msbuild /version & cl (Windows)
代码语言:javascript
运行
复制
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.9.21.664Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27043 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]
  • 模块:零

详细输出(来自npm或node):

代码语言:javascript
运行
复制
me@me-PC0 D:\Desktop\myapp
# node-gyp configure --msvs_version=2017
gyp info it worked if it ends with ok
gyp info using node-gyp@7.1.0
gyp info using node@12.18.3 | win32 | x64
gyp info find Python using Python version 3.8.5 found at "C:\Python\Python38\python.exe"
gyp ERR! find VS
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"
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 - could not find MSBuild in registry for 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\me\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\me\AppData\Roaming\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
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.18362
gyp ERR! command "C:\\Apps\\nodejs\\node.exe" "C:\\Users\\me\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--msvs_version=2017"
gyp ERR! cwd D:\Desktop\myapp
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok

我试过的东西都没有用

  • Desktop Development Kit for C++重新安装VS 2017
  • 重新安装节点和npm
  • 在Admin、Admin PowerShell、Admin VC2017 Dev命令提示符中运行相同的命令
  • 手动将VCINSTALLDIR环境变量设置为:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\
  • 运行npm config set msvs_version 2017 --global,然后npm config get msvs_version给我2017年
  • 重新启动PC的每一步

我在路上的每一步都犯了同样的错误。

进一步的尝试

我已经对我的整个nodejs安装进行了核弹,并重新开始,但问题仍然存在。我所做的

  • 删除基于这个StackOverflow的答案的nodejs。
  • 使用官方nodejs站点上的x64安装程序重新安装nodejs for Windowsv12.18.3,允许安装程序安装额外的依赖项,如巧克力
  • 使用electron-forge创建一个空白电子应用程序:如下所示
代码语言:javascript
运行
复制
me@me-PC0 D:\Desktop
$ npx create-electron-app myapp
√ Initializing Project Directory
√ Initializing Git Repository
√ Locating custom template: "base"
√ Copying Starter Files
√ Initializing NPM Module
√ Installing Template Dependencies
√ Installing NPM Dependencies

me@me-PC0 D:\Desktop
$ cd myapp

me@me-PC0 D:\Desktop\myapp
$ npm start

> myapp@1.0.0 start D:\Desktop\myapp
> electron-forge start

√ Checking your system
√ Locating Application
√ Preparing native dependencies
√ Launching Application
  • 配置的VS npm使用的版本:npm config set msvs_version 2017npm config set msvs_version 2017 --global

这个应用程序一直运行到现在。然后..。

  • 已安装的依赖项零
代码语言:javascript
运行
复制
$ npm install zeromq --save-prod
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\extract-zip.cmd as it wasn't installed by D:\Desktop\myapp\node_modules\extract-zip
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\extract-zip as it wasn't installed by D:\Desktop\myapp\node_modules\extract-zip
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\rimraf.cmd as it wasn't installed by D:\Desktop\myapp\node_modules\rimraf
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\rimraf as it wasn't installed by D:\Desktop\myapp\node_modules\rimraf
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\semver.cmd as it wasn't installed by D:\Desktop\myapp\node_modules\semver
npm WARN rm not removing D:\Desktop\myapp\node_modules\.bin\semver as it wasn't installed by D:\Desktop\myapp\node_modules\semver

> zeromq@6.0.0-beta.6 install D:\Desktop\myapp\node_modules\zeromq
> node-gyp-build


> core-js@3.6.5 postinstall D:\Desktop\myapp\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: electron-installer-debian@^3.0.0 (node_modules\@electron-forge\maker-deb\node_modules\electron-installer-debian):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for electron-installer-debian@3.1.0: wanted {"os":"darwin,linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: electron-installer-redhat@^3.2.0 (node_modules\@electron-forge\maker-rpm\node_modules\electron-installer-redhat):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for electron-installer-redhat@3.2.0: wanted {"os":"darwin,linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN myapp@1.0.0 No repository field.

+ zeromq@6.0.0-beta.6
added 50 packages from 7 contributors, removed 32 packages, updated 401 packages and audited 460 packages in 61.306s

32 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
  • 运行电子伪造创建Windows发行版。
代码语言:javascript
运行
复制
$ npm run make

> myapp@1.0.0 make D:\Desktop\myapp
> electron-forge make

√ Checking your system
√ Resolving Forge Config
We need to package your application before we can make it
√ Preparing to Package Application for arch: x64
× Preparing native dependencies: 0 / 1

An unhandled error has occurred inside Forge:
Command failed with a non-zero return code (1):
D:\Desktop\myapp\node_modules\electron-rebuild\node_modules\.bin\node-gyp.cmd rebuild --target=10.1.0 --arch=x64 --dist-url=https://www.electronjs.org/headers --build-from-source

gyp ERR! find VS
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 VCINSTALLDIR not set, not running in VS Command Prompt
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 - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
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 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
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.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Desktop\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.1.0" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\me\AppData\Local\Temp\electron-packager\win32-x64\myapp-win32-x64\resources\app\node_modules\zeromq
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
Error: Command failed with a non-zero return code (1):
D:\Desktop\myapp\node_modules\electron-rebuild\node_modules\.bin\node-gyp.cmd rebuild --target=10.1.0 --arch=x64 --dist-url=https://www.electronjs.org/headers --build-from-source

gyp ERR! find VS
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 VCINSTALLDIR not set, not running in VS Command Prompt
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 - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
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 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
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.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Desktop\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.1.0" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\me\AppData\Local\Temp\electron-packager\win32-x64\myapp-win32-x64\resources\app\node_modules\zeromq
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
    at ChildProcess.<anonymous> (D:\Desktop\myapp\node_modules\@malept\cross-spawn-promise\src\index.ts:155:16)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:483:12)
    at ChildProcess.cp.emit (D:\Desktop\myapp\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp@1.0.0 make: `electron-forge make`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp@1.0.0 make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Roaming\npm-cache\_logs\2020-08-28T04_35_43_345Z-debug.log
  • 试图通过手动设置VCINSTALLDIR环境变量来修复此问题。
代码语言:javascript
运行
复制
set VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\
  • 然后再运行电子锻造。
代码语言:javascript
运行
复制
D:\Desktop\myapp>npm run make

> myapp@1.0.0 make D:\Desktop\myapp
> electron-forge make

√ Checking your system
√ Resolving Forge Config
We need to package your application before we can make it
√ Preparing to Package Application for arch: x64
× Preparing native dependencies: 0 / 1

An unhandled error has occurred inside Forge:
Command failed with a non-zero return code (1):
D:\Desktop\myapp\node_modules\electron-rebuild\node_modules\.bin\node-gyp.cmd rebuild --target=10.1.0 --arch=x64 --dist-url=https://www.electronjs.org/headers --build-from-source

gyp ERR! find VS
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"
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 - could not find MSBuild in registry for 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 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
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.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Desktop\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.1.0" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\me\AppData\Local\Temp\electron-packager\win32-x64\myapp-win32-x64\resources\app\node_modules\zeromq
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
Error: Command failed with a non-zero return code (1):
D:\Desktop\myapp\node_modules\electron-rebuild\node_modules\.bin\node-gyp.cmd rebuild --target=10.1.0 --arch=x64 --dist-url=https://www.electronjs.org/headers --build-from-source

gyp ERR! find VS
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"
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 - could not find MSBuild in registry for 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 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at D:\Desktop\myapp\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
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.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\Desktop\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.1.0" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\me\AppData\Local\Temp\electron-packager\win32-x64\myapp-win32-x64\resources\app\node_modules\zeromq
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
    at ChildProcess.<anonymous> (D:\Desktop\myapp\node_modules\@malept\cross-spawn-promise\src\index.ts:155:16)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:483:12)
    at ChildProcess.cp.emit (D:\Desktop\myapp\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp@1.0.0 make: `electron-forge make`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp@1.0.0 make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Roaming\npm-cache\_logs\2020-08-28T04_40_16_364Z-debug.log
  • 还试图黑入D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js节点-gyp的visual studio定位器代码,以便将amd64插入到行中。
代码语言:javascript
运行
复制
if (versionYear === 2017) {
        return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
}
if (versionYear === 2019) {
    return path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
}

使他们成为

代码语言:javascript
运行
复制
if (versionYear === 2017) {
        return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'amd64', 'MSBuild.exe')
}
if (versionYear === 2019) {
        return path.join(info.path, 'MSBuild', 'Current', 'Bin', 'amd64', 'MSBuild.exe')
}
  • 然后再次运行npm run make。与前一步相同的错误。

这是我的构建环境

代码语言:javascript
运行
复制
D:\Desktop\myapp>npm config get msvs_version
2017

D:\Desktop\myapp>npm config get python
C:\Python\Python38\pythonw.exe

Python3.8是来自python.org的64位版本。

问题

我遗漏了什么?我应该忘记VS2017吗?我的项目使用VS2017进行C++开发,所以我恐怕不能改变这一点。但是我应该安装VS2015吗?

令人困惑的是,在node README.md上,它首先说

发射cmd,npm config set msvs_version 2017

稍后在How to Use中,它会说:

代码语言:javascript
运行
复制
Auto-detection fails for Visual C++ Build Tools 2015, so --msvs_version=2015 needs to be added (not needed when run by npm as configured above):

$ node-gyp configure --msvs_version=2015

这个版本差异是怎么回事?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-29 00:23:19

终于自己想出来了。

元凶

Visual环境变量LIB在我的本地计算机上受到污染。在其中的某些路径中存在一些非法字符,这会导致node-gyp解析问题。这些字符修好后,问题就消失了。

此外,我在问题中提到的node-gyp源代码中的64位修复也是必要的:

代码语言:javascript
运行
复制
// D:\Desktop\myapp\node_modules\node-gyp\lib\find-visualstudio.js

if (versionYear === 2017) {
    return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'amd64', 'MSBuild.exe')
}
if (versionYear === 2019) {
    return path.join(info.path, 'MSBuild', 'Current', 'Bin', 'amd64', 'MSBuild.exe')
}

我是怎么找到的

我真的必须深入到node-gyp源代码中才能找到问题。它定位Visual安装的方式是通过一个PowerShell命令,该命令调用另一个执行OS查询工作的C#脚本Find-VisualStudio.cs

不幸的是,这个node-gyp命令的错误日志没有反映在立即的或日志中。在我拔出命令并在PowerShell中运行之后,,瞧!PowerShell命令运行中的底层系统日志显示了我的LIB变量有问题。

德育课

  • 经验法则:保持Visual环境变量的原样。
  • JS/节点生态系统具有复杂的依赖关系。您必须通过进入源代码来了解发生了什么事情来弄脏您的手。
  • 考虑到生态系统的速度,过时的提示可能会让你偏离正确的轨道,“过时”可能意味着半年或几个月前。
票数 2
EN

Stack Overflow用户

发布于 2020-08-28 10:10:42

尝试使用windows-build-tools npm包:https://www.npmjs.com/package/windows-build-tools。它是一个专门为Windows上的本地构建设置环境而设计的包。

您只需要全局安装它:

代码语言:javascript
运行
复制
npm install --global windows-build-tools

考虑到您现有的所有配置,这并不能保证工作,但是在一个干净的系统上,这本身就足以获得一个正常运行的构建环境。如果你仍然有麻烦,他们的Github问题跟踪器&自述文件(https://github.com/felixrieseberg/windows-build-tools)有很多建议。祝好运!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63627716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档