question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

electron Headers (headersDir) parameter does not work on API

See original GitHub issue

I’ve been working through this API now for 2 weeks and it is basically undocumented ( #77 ) and unusable ( #84 ) when it comes to Windows and building anything but the default options.

For the methods

  • installNodeHeaders
  • rebuildNativeModules

the third parameter (headersDir ) on installNodeHeaders function in the documented README are supposed to be the location of the electron headers for the recompile. However, this parameter MUST always be the location of the headers directory inside the actual electron-rebuild package. The rebuildNativeModules function will fail EVERY time if this value is not the equivalent of something like

var electronHeaders = path.resolve(__dirname, './node_modules/electron-rebuild/lib/headers');

literally, nothing else will work for this parameter. Which makes it not only useless but incorrect in the README documentation.

Even worse is the rebuildNativeModules function which says (in the documentation on the README) that the 3rd parameter is the headersDir parameter as well. However, this is FALSE. The third parameter to this function MUST BE the name of the module you are trying to rebuild. You CAN leave this third parameter blank (as in ‘’) but you MUST include it, or the function will fail badly. (leaving it blank will cause the function to simply apply the rebuild to all modules, which is what almost everyone wants most of the time) The headersDir parameter for the rebuildNativeModules function MUST be the 4th parameter, and it MUST be the same exact value as noted above. It’s not assignable or configurable to anything else. If you wish to use this parameter it is required to be in that fixed location. Which again, makes it useless as a parameter.

What this means is that the BEST way to use these two commands is simply to leave off the optional parameters, since they are either incorrectly documented, useless or fail consistently.

All of this could have been avoided simply by having actual help either on the documentation or the command line.

Here is an example of an ACTUAL working usage of this API, which belies the formally documented parameter definitions (for both functions) given on the main page:

    var nodemods = './node_modules';
    var electronCMD = nodemods + '/.bin/electron.cmd';

    var electronHeaders = path.resolve(__dirname, nodemods + '/electron-rebuild/lib/headers');

    eRebuild.shouldRebuildNativeModules(electronCMD)
      .then(function(shouldBuild) {
          if (!shouldBuild) {
              return true;
          }

          return eRebuild.installNodeHeaders(electronVersion, 'https://atom.io/download/atom-shell', electronHeaders)
            .then(function () {
                eRebuild.rebuildNativeModules(electronVersion, nodemods, '', electronHeaders);
            }).then(function () {
                eRebuild.preGypFixRun(nodemods, true, electronCMD);
            });
      })
      .catch(function(e) {
          log('Building modules didn\'t work: ' + e);
      });

There are other problems with this API (the arch parameters do NOT work as well), but I will document that in another issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MarshallOfSoundcommented, Jan 5, 2017
0reactions
corvinrokcommented, Jan 5, 2017

using the new version, it appears I have to use the keyword “default” in my gulp script as follows. Does this seem correct?

gulp.task('erebuild', ['clean-erebuild'], function () {
    var eRebuild = require('electron-rebuild');
    var process = require('process');
    var arch = process.arch;

    eRebuild.default(__dirname, electronVersion, arch)
        .then(function () {
            console.info('Electron Rebuild Successful');
            return true;
        }).catch(function(e) {
            log('Rebuilding modules against Electron didn\'t work: ' + e);
        });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

parameters? documentation? #77 - electron/electron-rebuild
I'm trying to use electron-rebuild in the cli, but how am I supposed to ... electron Headers (headersDir) parameter does not work on...
Read more >
Electron NET response does not deliver headers periodically ...
For that, i am taking the last-modified header parameter from the response.headers i am getting back from the request via net from @electron/ ......
Read more >
HTTP REST API Calls in ElectronJS - GeeksforGeeks
This tutorial will demonstrate how to make HTTP REST API calls in Electron using the net module and the advantages and features of...
Read more >
Electron Documentation Style Guide
The type of argument is notated by either JavaScript primitives (e.g. string , Promise , or Object ), a custom API structure like...
Read more >
Bypassing CORS with Electron. Using onHeadersReceived
Sometimes your Electron app needs to bypass CORS. ... and wish to send the header anyways; So we need to fix Access-Control-Allow-Headers ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found