gpt4 book ai didi

node.js - `npm config set msvs_version 2015 --global`设置的标志未通过 Electron 重建兑现

转载 作者:行者123 更新时间:2023-12-03 12:26:30 26 4
gpt4 key购买 nike

问题:

从VS 2013升级到VS 2015后,我最初在构建应用程序时遇到了问题,但是通过设置msvs_version 2015解决了该问题。尽管该命令适用于npm install(及其 Node 编译),但在electron-rebuild阶段却以某种方式被忽略了。

细节:

创刊号

具体来说,我的构建过程曾遇到此问题(首次升级时):
22:07:39 c:\work-projects\my-application>c:\CM\elevated_cmd.exe /C "npm install > npm_install.log"

22:22:38
22:22:38 c:\work-projects\my-application>type npm_install.log
22:22:38
22:22:38 > libxmljs-mt@0.16.1 install c:\work-projects\my-application\node_modules\libxmljs-mt
22:22:38 > node-gyp rebuild
22:22:38
22:22:38
22:22:38 c:\work-projects\my-application\node_modules\libxmljs-mt>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
22:22:38 Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
22:22:38 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [c:\work-projects\my-application\node_modules\libxmljs-mt\build\xmljs.vcxproj]

初始解决方案

但这很快通过以下命令设置得以解决:npm config set msvs_version 2015 --global
当前的问题

一旦我在上面设置了命令,一切似乎就可以正常工作了。 (在npm install期间发生的初始编译开始工作正常)。但是,一旦到达使用electron-rebuild的构建部分,我发现返回了相同的错误,但仅在 Electron 重建期间,如下所示:
13:15:32 c:\work-projects\my-application>c:\CM\elevated_cmd.exe /C "gulp erebuild > erebuild.log"

13:16:05
13:16:05 c:\work-projects\my-application>type erebuild.log
13:16:05 [13:15:41] Using gulpfile c:\work-projects\my-application\gulpfile.js
13:16:05 [13:15:41] Starting 'erebuild'...
13:16:05 [13:15:41] Finished 'erebuild' after 394 ms
13:16:05 [13:16:04] Rebuilding modules against Electron didn't work: Error: gyp info it worked if it ends with ok
13:16:05 gyp info using node-gyp@3.6.2
13:16:05 gyp info using node@7.10.1 | win32 | x64
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/iojs-v1.8.2-beta.4.tar.gz
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/iojs-v1.8.2-beta.4.tar.gz
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/SHASUMS256.txt
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/win-x64/iojs.lib
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/win-x86/iojs.lib
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/win-x64/iojs.lib
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/SHASUMS256.txt
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/win-x86/iojs.lib
13:16:05 gyp info spawn C:\Python27\python.exe
13:16:05 gyp info spawn args [ 'c:\\work-projects\\my-application\\node_modules\\node-gyp\\gyp\\gyp_main.py',
13:16:05 gyp info spawn args 'binding.gyp',
13:16:05 gyp info spawn args '-f',
13:16:05 gyp info spawn args 'msvs',
13:16:05 gyp info spawn args '-G',
13:16:05 gyp info spawn args 'msvs_version=auto',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\build\\config.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\common.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\node-gyp\\addon.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4\\common.gypi',
13:16:05 gyp info spawn args '-Dlibrary=shared_library',
13:16:05 gyp info spawn args '-Dvisibility=default',
13:16:05 gyp info spawn args '-Dnode_root_dir=C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4',
13:16:05 gyp info spawn args '-Dnode_gyp_dir=c:\\work-projects\\my-application\\node_modules\\node-gyp',
13:16:05 gyp info spawn args '-Dnode_lib_file=C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4\\<(target_arch)\\iojs.lib',
13:16:05 gyp info spawn args '-Dmodule_root_dir=c:\\work-projects\\my-application\\node_modules\\libxml-xsd',
13:16:05 gyp info spawn args '-Dnode_engine=v8',
13:16:05 gyp info spawn args '--depth=.',
13:16:05 gyp info spawn args '--no-parallel',
13:16:05 gyp info spawn args '--generator-output',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\build',
13:16:05 gyp info spawn args '-Goutput_dir=.' ]
13:16:05 gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
13:16:05 gyp info spawn args [ 'build/binding.sln',
13:16:05 gyp info spawn args '/clp:Verbosity=minimal',
13:16:05 gyp info spawn args '/nologo',
13:16:05 gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
13:16:05 Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
13:16:05 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [c:\work-projects\my-application\node_modules\libxml-xsd\build\node-libxml-xsd.vcxproj]
13:16:05 gyp ERR! build error
13:16:05 gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
13:16:05 gyp ERR! stack at ChildProcess.onExit (c:\work-projects\my-application\node_modules\node-gyp\lib\build.js:258:23)
13:16:05 gyp ERR! stack at emitTwo (events.js:106:13)
13:16:05 gyp ERR! stack at ChildProcess.emit (events.js:194:7)
13:16:05 gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
13:16:05 gyp ERR! System Windows_NT 6.3.9600
13:16:05 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "c:\\work-projects\\my-application\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.8.2-beta.4" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source"
13:16:05 gyp ERR! cwd c:\work-projects\my-application\node_modules\libxml-xsd
13:16:05 gyp ERR! node -v v7.10.1
13:16:05 gyp ERR! node-gyp -v v3.6.2
13:16:05 gyp ERR! not ok
13:16:05
13:16:05 Failed with exit code: 1

相关代码

我大呼 Electron 重建的呼声非常简单明了,所以我怀疑它会揭示很多,但是这里是:
```

gulp.task('erebuild', , function () {
var eRebuild = require('electron-rebuild').rebuild;
var arch = process.arch;
eRebuild(
{buildPath: __dirname,
electronVersion: electronVersion,
arch: arch
})
.then(function () {
log('electron version: ' + electronVersion + ' arch version: ' + arch);
log('Electron Rebuild Successful');
return true;
}).catch(function (e) {
log('Rebuilding modules against Electron didn\'t work: ' + e);
});
});

```

我应该在electron-rebuild调用中添加一个选项来强制将msvs_version值赋予吗?
electron-rebuild是否应该像 npm install一样自动使用此值?

我注意到在gyp配置参数的 electron-rebuild显示中, msvs_version=auto作为其设置而不是 2015出现(请参见上面“当前问题”部分的大约1/3)。如何为 auto赋值或指向 2015(或者如何使 electron-rebuild显式使用2015而不是 auto)?我不完全确定应该如何处理。这是 electron-rebuild中的错误吗? electron-rebuild是否应具有指定 msvs_version的选项?还是 auto应该是我在配置中某个位置设置的值?如果可以,怎么办?

最佳答案

最后,通过尝试使electron-rebuild以某种方式查看npm msvs_version设置所设置的配置,无法解决这种情况。在我的情况下,MS Visual Studio 2015和2017的工具集都是在此过程中安装的,似乎某些安装/卸载过程引起了问题。

我为解决此问题所做的事情是:

  • 首先,我卸载了所有版本的MSBuild工具,MS Visual Studio。
    (以我为例,是2015年和2017年),甚至是Python。
  • 然后,我按照“Windows”特定说明中的“选项1”在以下位置进行操作:
    通过执行https://www.npmjs.com/package/node-gyp#installationnpm install --global --production windows-build-tools
  • 因为所有VS,MSBuild工具和Python均由windows-build-tools软件包安装后,Python设置似乎
    有点不完整。为了解决这个问题,我做了以下工作:

    a)配置 Node 以查看Python(运行npm config set python
    "C:\Users\MyUser\.windows-build-tools\python27\python.exe")

    b)设置PYTHON环境变量。您可以通过使用控制面板或在较高的CMD上运行来执行此操作
    set PYTHON "C:\Users\MyUser\.windows-build-tools\python27\python.exe"

  • 之后,一切正常。

    关于node.js - `npm config set msvs_version 2015 --global`设置的标志未通过 Electron 重建兑现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48412365/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com