@electron/packager, electron-builder, electron-packager, and electron-rebuild are essential tools in the Electron ecosystem for converting web applications into desktop executables. @electron/packager is the current official tool for packaging Electron apps into OS-specific bundles without building installers. electron-builder is a comprehensive solution that handles packaging, building installers (DMG, EXE, deb), code signing, and auto-updates. electron-packager is the legacy predecessor to @electron/packager and is no longer recommended for new projects. electron-rebuild is a utility specifically designed to rebuild native Node.js modules against the correct Electron headers, ensuring compatibility with the bundled Node version.
Building a production-ready Electron application requires more than just writing JavaScript. You need to bundle the Chromium runtime, package your source code into executables, handle native dependencies, and often create installers. The ecosystem offers distinct tools for these tasks: @electron/packager, electron-builder, the legacy electron-packager, and electron-rebuild. Let's examine how they fit into a professional build pipeline.
The most critical distinction is between packaging (creating the app bundle) and building (creating the installer).
@electron/packager focuses strictly on packaging. It takes your source and the Electron binary and outputs a folder structure (e.g., MyApp.app or MyApp.exe). It does not create installers by default.
# @electron/packager: CLI usage
npx @electron/packager ./src MyApp --platform=darwin --arch=x64
# Output: ./MyApp-darwin-x64/MyApp.app
electron-builder handles the entire lifecycle. It packages the app AND creates installers (DMG, NSIS, AppImage, etc.). It also manages code signing and notarization automatically.
# electron-builder: CLI usage
npx electron-builder --mac --win
# Output: ./dist/MyApp.dmg, ./dist/MyApp Setup.exe
electron-packager (legacy) functioned similarly to @electron/packager but is no longer maintained for new feature work. It produces app bundles but lacks the modern scoped package structure.
# electron-packager: Legacy CLI usage
npx electron-packager ./src MyApp --platform=darwin --arch=x64
# Output: ./MyApp-darwin-x64/MyApp.app
electron-rebuild does not package apps. It compiles native modules. You run this before packaging to ensure C++ addons match Electron's Node version.
# electron-rebuild: CLI usage
npx electron-rebuild -v 30.0.0 -f
# Rebuilds node_modules against Electron v30 headers
Electron bundles its own version of Node.js, which often differs from your system's Node version. Native modules (like sqlite3 or node-serialport) must be recompiled to work.
@electron/packager does not automatically rebuild native modules. You must run a rebuild step separately or use a hook.
// @electron/packager: Programmatic usage with hook
const packager = require('@electron/packager');
await packager({
dir: './src',
name: 'MyApp',
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
// Manually trigger rebuild logic here
callback();
}]
});
electron-builder has native module rebuilding built-in. It detects node-gyp dependencies and rebuilds them automatically during the build process.
// electron-builder: package.json config
{
"build": {
"npmRebuild": true,
"nativeRebuilder": {
"parallel": true
}
}
}
electron-packager shares the same limitation as its successor. It requires manual intervention for native modules.
// electron-packager: Programmatic usage
const packager = require('electron-packager');
await packager({
dir: './src',
name: 'MyApp',
// No built-in native rebuild, requires external script
});
electron-rebuild is the dedicated solution for this problem. It is often used alongside @electron/packager to fill the gap.
// electron-rebuild: Programmatic usage
const Rebuild = require('electron-rebuild').default;
const rebuilder = new Rebuild({
buildPath: __dirname,
electronVersion: '30.0.0',
arch: 'x64'
});
await rebuilder.rebuild();
Configuration style varies from simple CLI flags to complex JSON schemas.
@electron/packager uses a straightforward API or CLI flags. It is minimalistic.
// @electron/packager: JS API
const options = {
dir: '.',
name: 'MyApp',
platform: 'linux',
arch: 'x64',
electronVersion: '30.0.0'
};
electron-builder relies heavily on package.json or electron-builder.yml. It is opinionated and verbose but powerful.
# electron-builder: electron-builder.yml
appId: com.example.app
mac:
category: public.app-category.productivity
target: dmg
win:
target: nsis
electron-packager uses a similar API to @electron/packager but is tied to the legacy namespace.
// electron-packager: JS API
const options = {
dir: '.',
name: 'MyApp',
platform: 'linux',
arch: 'x64'
};
electron-rebuild is configured via CLI flags or a constructor object, focusing solely on build paths and versions.
# electron-rebuild: CLI flags
npx electron-rebuild --path ./src --version 30.0.0 --force
For macOS and Windows distribution, signing is mandatory.
@electron/packager supports signing via plugins or the osxSign option (often delegated to @electron/osx-sign). It does not handle notarization out of the box.
// @electron/packager: Signing config
await packager({
...options,
osxSign: {
identity: 'Developer ID Application: My Name'
}
});
electron-builder automates signing and notarization. It reads environment variables (like CSC_LINK) and handles the entire flow.
// electron-builder: package.json
{
"build": {
"mac": {
"hardenedRuntime": true,
"gatekeeperAssess": false
}
}
}
electron-packager supports signing similarly to @electron/packager but lacks ongoing support for new OS security requirements.
// electron-packager: Signing config
await packager({
...options,
osxSign: true
});
electron-rebuild does not handle signing. It is strictly for compilation.
# electron-rebuild: No signing capabilities
# N/A
Shipping the app is only step one; updating it is another.
@electron/packager provides no update mechanism. You must implement electron-updater or a custom solution manually.
// @electron/packager: Manual update implementation
// Requires separate library like electron-updater
const { autoUpdater } = require('electron-updater');
autoUpdater.checkForUpdatesAndNotify();
electron-builder integrates tightly with electron-updater. It publishes artifacts to GitHub, S3, or Spaces automatically.
// electron-builder: Publish config
{
"build": {
"publish": {
"provider": "github",
"owner": "my-org",
"repo": "my-app"
}
}
}
electron-packager like its successor, requires manual update implementation.
// electron-packager: Manual update implementation
// Requires separate library setup
const { autoUpdater } = require('electron-updater');
electron-rebuild is unrelated to app updates.
# electron-rebuild: N/A
| Feature | @electron/packager | electron-builder | electron-packager | electron-rebuild |
|---|---|---|---|---|
| Primary Role | App Bundling | Full Build & Installers | Legacy App Bundling | Native Module Rebuild |
| Installers | β No | β Yes (DMG, EXE, etc.) | β No | β No |
| Native Modules | β οΈ Manual/Hooks | β Automatic | β οΈ Manual/Hooks | β Dedicated Tool |
| Code Signing | β οΈ Via Options/Plugin | β Automated | β οΈ Via Options/Plugin | β No |
| Auto Updates | β Manual Setup | β Integrated | β Manual Setup | β No |
| Status | β Active (Official) | β Active | β οΈ Legacy/Deprecated | β Active (Utility) |
electron-builder is the heavy lifter ποΈ. If you need to ship a signed, installable product with auto-updates tomorrow, choose this. It abstracts the complexity of notarization and installer creation, which saves weeks of configuration time.
@electron/packager is the precision instrument π¬. Use this if you are building a custom CI/CD pipeline where you want to separate packaging from signing and installer creation. It is also the correct choice if you are distributing portable apps (just the folder) rather than installers.
electron-packager is the legacy tool π°οΈ. It exists for backwards compatibility. Do not start new projects with it. Migrate existing projects to @electron/packager to ensure compatibility with future Electron releases.
electron-rebuild is the specialist π§. You might not need it directly if you use electron-builder, but if you use @electron/packager and have native dependencies, this tool (or its logic integrated into your scripts) is mandatory to prevent runtime crashes.
Final Thought: For most teams, electron-builder offers the best balance of power and convenience. However, understanding @electron/packager is valuable for debugging build issues, as electron-builder often uses packaging logic similar to it under the hood. Always ensure native modules are rebuilt regardless of which packager you choose.
Choose @electron/packager if you need a straightforward, low-level tool to package your app into executable folders for multiple platforms without generating installers. It is ideal for teams that want full control over the build pipeline and prefer to handle code signing, notarization, and installer creation with separate, specialized tools. This package is the official successor to the legacy electron-packager.
Choose electron-builder if you want an all-in-one solution that manages packaging, installer creation, code signing, notarization, and auto-update distribution. It is best for production applications where you need to ship signed installers (like .dmg or .exe) and manage release channels without configuring multiple disparate tools.
Do NOT choose electron-packager for new projects. It is the legacy version of the packaging tool and has been superseded by @electron/packager. Existing projects using this should plan a migration to the scoped package to ensure continued security updates and compatibility with modern Electron versions.
Choose electron-rebuild if your application depends on native Node.js modules (C++ addons) that need to be compiled against Electron's specific Node headers. While often integrated into other build tools, it is essential as a standalone utility or script hook when you encounter native module version mismatch errors during development or CI builds.
Package your Electron app into OS-specific bundles (.app, .exe, etc.) via JavaScript or the command line.
Supported Platforms | Installation | Usage | Contributing | Support | Related Apps/Libraries | FAQ | Release Notes
Electron Packager is a command line tool and Node.js library that bundles Electron-based application source code with a renamed Electron executable and supporting files into folders ready for distribution.
For creating distributables like installers and Linux packages, consider using either Electron Forge (which uses Electron Packager internally), or one of the related Electron tools, which utilizes Electron Packager-created folders as a basis.
Note that packaged Electron applications can be relatively large. A zipped, minimal Electron
application is approximately the same size as the zipped prebuilt binary for a given target
platform, target arch, and Electron version
(files named electron-v${version}-${platform}-${arch}.zip).
Electron Packager is known to run on the following host platforms:
It generates executables/bundles for the following target platforms:
win32, for x861, x86_64, and arm64 architectures)darwin) / Mac App Store (also known as mas)2 (for x86_64, arm64, and universal architectures)This module requires Node.js 22.12.0 or higher to run.
npm install --save-dev @electron/packager
It is not recommended to install @electron/packager globally.
JavaScript API usage can be found in the API documentation.
Running Electron Packager from the command line has this basic form:
npx @electron/packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]
This will:
<out>/<appname>-<platform>-<arch> (this can be customized via an optional flag)--platform and --arch can be omitted, in two cases:
--all instead, bundles for all valid combinations of target
platforms/architectures will be created.For an overview of the other optional flags, run electron-packager --help or see
usage.txt. For
detailed descriptions, see the API documentation.
For flags that are structured as objects, you can pass each option as via dot notation as such:
npx @electron/packager --flag.foo="bar"
# will pass in { flag: { foo: "bar"} } as an option to the Electron Packager API
If appname is omitted, this will use the name specified by "productName" or "name" in the nearest package.json.
Characters in the Electron app name which are not allowed in all target platforms' filenames
(e.g., /), will be replaced by hyphens (-).
You should be able to launch the app on the platform you built for. If not, check your settings and try again.
Be careful not to include node_modules you don't want into your final app. If you put them in
the devDependencies section of package.json, by default none of the modules related to those
dependencies will be copied in the app bundles. (This behavior can be turned off with the
prune: false API option or --no-prune CLI flag.) In addition, folders like .git and
node_modules/.bin will be ignored by default. You can use --ignore to ignore files and folders
via a regular expression (not a glob pattern).
Examples include --ignore=\.gitignore or --ignore="\.git(ignore|modules)".
Let's assume that you have made an app based on the minimal-repro repository on an Apple Silicon macOS device with the following file structure:
foobar
βββ package.json
βββ index.html
βββ [β¦other files, like the app's LICENSEβ¦]
βββ script.js
β¦and that the following is true:
@electron/packager is installed locallyproductName in package.json has been set to Foo Barelectron module is in the devDependencies section of package.json, and set to the exact version of 38.3.0.npm install for the Foo Bar app has been run at least onceWhen one runs the following command for the first time in the foobar directory:
npx @electron/packager .
@electron/packager will do the following:
sourcedirappname from the productName in package.jsonappVersion from the version in package.jsonplatform and arch from the host, in this example, darwin platform and arm64 arch.~/.electron)Foo Bar.appFoo Bar.app in foobar/Foo Bar-darwin-arm64/ (since an out directory was not specified, it used the current working directory)The file structure now looks like:
foobar
βββ Foo Bar-darwin-x64
βΒ Β βββ Foo Bar.app
βΒ Β βΒ Β βββ [β¦Mac app contentsβ¦]
β βββ LICENSE [the Electron license]
β βββ version
βββ [β¦other application bundles, like "Foo Bar-win32-x64" (sans quotes)β¦]
βββ package.json
βββ index.html
βββ [β¦other files, like the app's LICENSEβ¦]
βββ script.js
The Foo Bar.app folder generated can be executed by a system running macOS, which will start the packaged Electron app.
This is also true of the Windows x64 build on a Windows device (via Foo Bar-win32-x64/Foo Bar.exe), and so on.
Windows:
macOS:
Linux:
These Node modules utilize Electron Packager API hooks:
Windows x86 (ia32) and Linux armv7l builds are only published for Electron <= 43 β starting with Electron 44.0.0-alpha.4, official builds for these architectures are no longer provided. β© β©2
Note for macOS / Mac App Store target bundles: the .app bundle can only be signed when building on a host macOS platform. β©