Kim Gentes
Kim Gentes

Reputation: 1628

Flag set by `npm config set msvs_version 2015 --global` is not being honored by electron-rebuild

Issue:

I originally had a problem building my application after upgrading from VS 2013 to VS 2015, but that problem was solved by setting msvs_version 2015. While that worked for the npm install (and its node compiles), it somehow is being ignored at the electron-rebuild stage.

Details:

Initial issue

Specifically, my build process once had this issue (when I first upgraded): 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 > [email protected] 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]

Initial solution

But that was quickly remedied by this command setting: npm config set msvs_version 2015 --global

Current Issue

Once I set the command above, things seemed to be working fine. (the initial compiles that happen during npm install started working fine). But once I got to the build part that uses electron-rebuild, I found the same error returned but only during the electron-rebuild compiles, as follows: 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 [email protected] 13:16:05 gyp info using [email protected] | 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

Pertinent Code

My gulp call of electron-rebuild is pretty straightforward and crisp, so I doubt it will reveal much, but here it is :
```

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

```

Is there an option I should be adding to my electron-rebuild call to force the msvs_version value to it?

Shouldn't electron-rebuild automatically be using this value, as npm install does?

I notice in the electron-rebuild display of gyp configuration params that msvs_version=auto appears as its setting rather than 2015 (see about 1/3 the way down in the "Current Issue" section above). How do I assign auto the value of/or pointing to 2015 (or how do I get electron-rebuild to explicitly use 2015 rather than auto)? I am not completely sure how this should be approached. Is this a bug in electron-rebuild? Should electron-rebuild have an option to specify msvs_version? Or is auto supposed to be a value that I set somewhere in the configuration? If so how?

Upvotes: 1

Views: 10323

Answers (1)

Kim Gentes
Kim Gentes

Reputation: 1628

In the end, this situation was not resolvable by trying to get electron-rebuild to somehow see the configuration set by npm msvs_version setting. In my situation, the toolsets of MS Visual Studio 2015 and 2017 were both installed during the process and it seems that some of this install/uninstall process had caused issues.

What I did to resolve this issue was:

  1. First, I uninstalled all versions of MSBuild tools, MS Visual Studio (2015 and 2017, in my case) and even Python.

  2. I then followed "Option 1" of the "Windows" specific instructions at https://www.npmjs.com/package/node-gyp#installation by doing the npm install --global --production windows-build-tools

  3. Because all the VS, MSBuild tools AND Python were re-installed by windows-build-tools package install, the Python settings seemed to be slightly incomplete. To resolve that I did the following:

    a) Configure Node to see Python (run npm config set python "C:\Users\MyUser\.windows-build-tools\python27\python.exe")

    b) Set the PYTHON environment variable. You can do this by either using the CONTROL PANEL or at an elevated CMD you can run

    set PYTHON "C:\Users\MyUser\.windows-build-tools\python27\python.exe"

After that, everything worked.

Upvotes: 3

Related Questions