electron-rebuild

Electron supporting package to rebuild native node modules against the currently installed electron

Please use @electron/rebuild moving forward. There is no API change, just a package name change
Last updated 5 years ago by marshallofsound .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install electron-rebuild 
SYNC missed versions from official npm registry.

Electron Rebuild

CircleCI NPM Coverage Status

This executable rebuilds native Node.js modules against the version of Node.js that your Electron project is using. This allows you to use native Node.js modules in Electron apps without your system version of Node.js matching exactly (which is often not the case, and sometimes not even possible).

How does it work?

Install the package with --save-dev:

npm install --save-dev electron-rebuild

Then, whenever you install a new npm package, rerun electron-rebuild:

$(npm bin)/electron-rebuild

Or if you're on Windows:

.\node_modules\.bin\electron-rebuild.cmd

If you have a good node-gyp config but you see an error about a missing element on Windows like Could not load the Visual C++ component "VCBuild.exe", try to launch electron-rebuild in an npm script:

"scripts": {
  "rebuild": "electron-rebuild -f -w yourmodule"
}

and then

npm run rebuild

What are the requirements?

Node v12.13.0 or higher is required. Building native modules from source uses node-gyp, refer to the link for its installation/runtime requirements.

CLI Arguments

Usage: electron-rebuild --version [version] --module-dir [path]

Options:
  -h, --help                   Show help                               [boolean]
  -v, --version                The version of Electron to build against
  -f, --force                  Force rebuilding modules, even if we would skip
                               it otherwise
  -a, --arch                   Override the target architecture to something
                               other than your system's
  -m, --module-dir             The path to the app directory to rebuild
  -w, --which-module           A specific module to build, or comma separated
                               list of modules. Modules will only be rebuilt if they
                               also match the types of dependencies being rebuilt
                               (see --types).
  -e, --electron-prebuilt-dir  The path to the prebuilt electron module
  -d, --dist-url               Custom header tarball URL
  -t, --types                  The types of dependencies to rebuild.  Comma
                               separated list of "prod", "dev" and "optional".
                               Default is "prod,optional"
  -p, --parallel               Rebuild in parallel, this is enabled by default
                               on macOS and Linux
  -s, --sequential             Rebuild modules sequentially, this is enabled by
                               default on Windows
  -o, --only                   Only build specified module, or comma separated
                               list of modules. All others are ignored.
  -b, --debug                  Build debug version of modules
  --prebuild-tag-prefix        GitHub tag prefix passed to prebuild-install.
                               Default is "v"

Copyright 2016

How can I use this with Electron Forge?

This package is automatically used with Electron Forge when packaging an Electron app.

How can I integrate this into Electron Packager?

electron-rebuild provides a function compatible with the afterCopy hook for Electron Packager. For example:

import packager from 'electron-packager';
import rebuild from 'electron-rebuild';

packager({
  // … other options
  afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
    rebuild({ buildPath, electronVersion, arch })
      .then(() => callback())
      .catch((error) => callback(error));
  }],
  // … other options
});

How can I integrate this with prebuild?

If your module uses prebuild for creating prebuilt binaries, it also uses prebuild-install to download them. If this is the case, then electron-rebuild will run prebuild-install to download the correct binaries from the project's GitHub Releases instead of rebuilding them.

How can I integrate this into Grunt / Gulp / Whatever?

electron-rebuild is also a library that you can require into your app or build process. It has a very simple API:

import rebuild from 'electron-rebuild';

// Public: Rebuilds a node_modules directory with the given Electron version.
//
// options: Object with the following properties
//     buildPath - An absolute path to your app's directory.  (The directory that contains your node_modules)
//     electronVersion - The version of Electron to rebuild for
//     arch (optional) - Default: process.arch - The arch to rebuild for
//     extraModules (optional) - Default: [] - An array of modules to rebuild as well as the detected modules
//     onlyModules (optional) - Default: null - An array of modules to rebuild, ONLY these module names will be rebuilt.
//                                              The "types" property will be ignored if this option is set.
//     force (optional) - Default: false - Force a rebuild of modules regardless of their current build state
//     headerURL (optional) - Default: https://www.electronjs.org/headers - The URL to download Electron header files from
//     types (optional) - Default: ['prod', 'optional'] - The types of modules to rebuild
//     mode (optional) - The rebuild mode, either 'sequential' or 'parallel' - Default varies per platform (probably shouldn't mess with this one)
//     useElectronClang (optional) - Whether to use the clang executable that Electron used when building its binary. This will guarantee compiler compatibility

// Returns a Promise indicating whether the operation succeeded or not

A full build process might look something like:

const childProcess = require('child_process');
const pathToElectron = require('electron');

  rebuild({
    buildPath: __dirname,
    electronVersion: '1.4.12'
  })
    .then(() => console.info('Rebuild Successful'))
    .catch((e) => {
      console.error("Building modules didn't work!");
      console.error(e);
    });

Alternatives

  • require-rebuild patches require() to rebuild native node modules on the fly

Current Tags

  • 3.2.9                                ...           latest (2 years ago)

79 Versions

  • 3.2.9 [deprecated]           ...           2 years ago
  • 3.2.8 [deprecated]           ...           2 years ago
  • 3.2.7 [deprecated]           ...           3 years ago
  • 3.2.6 [deprecated]           ...           3 years ago
  • 3.2.5 [deprecated]           ...           3 years ago
  • 3.2.4 [deprecated]           ...           3 years ago
  • 3.2.3 [deprecated]           ...           3 years ago
  • 3.2.2 [deprecated]           ...           3 years ago
  • 3.2.1 [deprecated]           ...           3 years ago
  • 3.2.0 [deprecated]           ...           3 years ago
  • 3.1.1 [deprecated]           ...           3 years ago
  • 3.1.0 [deprecated]           ...           3 years ago
  • 3.0.0 [deprecated]           ...           3 years ago
  • 2.3.5 [deprecated]           ...           4 years ago
  • 2.3.4 [deprecated]           ...           4 years ago
  • 2.3.2 [deprecated]           ...           4 years ago
  • 2.3.1 [deprecated]           ...           4 years ago
  • 2.3.0 [deprecated]           ...           4 years ago
  • 2.2.0 [deprecated]           ...           4 years ago
  • 2.1.1 [deprecated]           ...           4 years ago
  • 2.1.0 [deprecated]           ...           4 years ago
  • 2.0.3 [deprecated]           ...           4 years ago
  • 2.0.2 [deprecated]           ...           4 years ago
  • 2.0.1 [deprecated]           ...           4 years ago
  • 2.0.0 [deprecated]           ...           4 years ago
  • 1.11.0 [deprecated]           ...           5 years ago
  • 1.10.1 [deprecated]           ...           5 years ago
  • 1.10.0 [deprecated]           ...           5 years ago
  • 1.9.0 [deprecated]           ...           5 years ago
  • 1.8.8 [deprecated]           ...           5 years ago
  • 1.8.7 [deprecated]           ...           5 years ago
  • 1.8.6 [deprecated]           ...           5 years ago
  • 1.8.5 [deprecated]           ...           5 years ago
  • 1.8.4 [deprecated]           ...           6 years ago
  • 1.8.3 [deprecated]           ...           6 years ago
  • 1.8.2 [deprecated]           ...           6 years ago
  • 1.8.1 [deprecated]           ...           6 years ago
  • 1.7.3 [deprecated]           ...           7 years ago
  • 1.7.2 [deprecated]           ...           7 years ago
  • 1.7.1 [deprecated]           ...           7 years ago
  • 1.7.0 [deprecated]           ...           7 years ago
  • 1.6.1 [deprecated]           ...           7 years ago
  • 1.6.0 [deprecated]           ...           7 years ago
  • 1.5.11 [deprecated]           ...           8 years ago
  • 1.5.10 [deprecated]           ...           8 years ago
  • 1.5.9 [deprecated]           ...           8 years ago
  • 1.5.8 [deprecated]           ...           8 years ago
  • 1.5.7 [deprecated]           ...           8 years ago
  • 1.5.6 [deprecated]           ...           8 years ago
  • 1.5.5 [deprecated]           ...           8 years ago
  • 1.5.4 [deprecated]           ...           8 years ago
  • 1.5.3 [deprecated]           ...           8 years ago
  • 1.5.2 [deprecated]           ...           8 years ago
  • 1.5.1 [deprecated]           ...           8 years ago
  • 1.5.0 [deprecated]           ...           8 years ago
  • 1.4.0 [deprecated]           ...           8 years ago
  • 1.3.0 [deprecated]           ...           8 years ago
  • 1.2.1 [deprecated]           ...           8 years ago
  • 1.2.0 [deprecated]           ...           8 years ago
  • 1.1.5 [deprecated]           ...           8 years ago
  • 1.1.4 [deprecated]           ...           8 years ago
  • 1.1.3 [deprecated]           ...           9 years ago
  • 1.1.2 [deprecated]           ...           9 years ago
  • 1.1.1 [deprecated]           ...           9 years ago
  • 1.1.0 [deprecated]           ...           9 years ago
  • 1.0.2 [deprecated]           ...           9 years ago
  • 1.0.1 [deprecated]           ...           9 years ago
  • 1.0.0 [deprecated]           ...           9 years ago
  • 0.2.5 [deprecated]           ...           9 years ago
  • 0.2.4 [deprecated]           ...           9 years ago
  • 0.2.3 [deprecated]           ...           9 years ago
  • 0.2.2 [deprecated]           ...           9 years ago
  • 0.2.1 [deprecated]           ...           9 years ago
  • 0.2.0 [deprecated]           ...           9 years ago
  • 0.1.4 [deprecated]           ...           10 years ago
  • 0.1.3 [deprecated]           ...           10 years ago
  • 0.1.2 [deprecated]           ...           10 years ago
  • 0.1.1 [deprecated]           ...           10 years ago
  • 0.1.0 [deprecated]           ...           10 years ago
Downloads
Total 66
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 40
Dependencies (9)
Dev Dependencies (15)

© 2010 - cnpmjs.org x YWFE | Home | YWFE