代码之家  ›  专栏  ›  技术社区  ›  Kim Gentes

electron rebuild不接受“npm config set msvs\U version 2015--global”设置的标志

  •  1
  • Kim Gentes  · 技术社区  · 7 年前

    问题:

    在从VS 2013升级到VS 2015后,我最初在构建应用程序时遇到了一个问题,但通过设置 msvs_version 2015 . 虽然这对 npm install (并且它的节点进行编译),在 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安装 开始工作正常)。但一旦我到了使用 电子重建 ,我发现返回了相同的错误,但仅在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

    相关代码

    我对电子重建的呼吁非常直截了当和清晰,所以我怀疑它会揭示很多,但这里是:
    ```

    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);
            });
    });
    

    ```

    是否有一个选项我应该添加到 电子重建 调用以强制msvs\U版本值?

    不应该 电子重建 自动使用此值,如 npm安装

    我注意到 电子重建 gyp配置参数的显示 msvs_version=auto 显示为其设置,而不是 2015 (请参见上文“最新版本”部分中的大约1/3)。如何分配 auto 或指向的值 2015 (或如何获得 电子重建 明确使用2015而不是 汽车 )? 我不完全确定应该如何处理这一问题。这是一个bug吗 电子重建 ? 应该 电子重建 具有指定选项 msvs_version ? 或者是 汽车 应该是我在配置中设置的值?如果是,怎么做?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Kim Gentes    7 年前

    最终,这种情况无法通过 electron-rebuild 以某种方式查看 npm msvs_version 背景在我的情况下,MS Visual Studio 2015和2017的工具集都是在安装过程中安装的,似乎其中一些安装/卸载过程导致了问题。

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

    1. 首先,我卸载了所有版本的MSBuild工具MS Visual Studio (就我而言,是2015年和2017年),甚至是Python。

    2. 然后,我按照“Windows”特定说明中的“选项1”在 https://www.npmjs.com/package/node-gyp#installation 通过执行 npm install --global --production windows-build-tools

    3. 因为所有的VS、MSBuild工具和Python都是由 windows-build-tools 安装包时,Python设置似乎 略不完整。为了解决这个问题,我做了以下工作:

      a) 配置节点以查看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"

    在那之后,一切都正常了。