@electron/packager vs electron-builder vs electron-packager vs electron-rebuild
Electron Application Packaging and Native Module Management
@electron/packagerelectron-builderelectron-packagerelectron-rebuildSimilar Packages:

Electron Application Packaging and Native Module Management

@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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@electron/packager0301282 kB11a month agoBSD-2-Clause
electron-builder014,65984.5 kB1043 months agoMIT
electron-packager0301145 kB113 years agoBSD-2-Clause
electron-rebuild01,123211 kB78-MIT

Electron Packaging Tools: Architecture, Workflow, and Native Modules

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.

πŸ“¦ Core Purpose: Packaging vs. Building Installers

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

πŸ”Œ Native Module Handling

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 Complexity

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

πŸ›‘οΈ Code Signing and Notarization

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

πŸ”„ Update Mechanisms

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

πŸ“Š Summary: Tool Responsibilities

Feature@electron/packagerelectron-builderelectron-packagerelectron-rebuild
Primary RoleApp BundlingFull Build & InstallersLegacy App BundlingNative 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)

πŸ’‘ The Big Picture

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.

How to Choose: @electron/packager vs electron-builder vs electron-packager vs electron-rebuild

  • @electron/packager:

    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.

  • electron-builder:

    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.

  • electron-packager:

    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.

  • electron-rebuild:

    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.

README for @electron/packager

@electron/packager

Package your Electron app into OS-specific bundles (.app, .exe, etc.) via JavaScript or the command line.

Test electron-nightly Canary Coverage Status npm API docs Discord

Supported Platforms | Installation | Usage | Contributing | Support | Related Apps/Libraries | FAQ | Release Notes


About

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).

Supported Platforms

Electron Packager is known to run on the following host platforms:

  • Windows (32/64 bit)
  • macOS (formerly known as OS X)
  • Linux (x86/x86_64)

It generates executables/bundles for the following target platforms:

  • Windows (also known as win32, for x861, x86_64, and arm64 architectures)
  • macOS (also known as darwin) / Mac App Store (also known as mas)2 (for x86_64, arm64, and universal architectures)
  • Linux (for x86, x86_64, armv7l1, arm64, and mips64el architectures)

Installation

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.

Usage

Via JavaScript

JavaScript API usage can be found in the API documentation.

From the command line

Running Electron Packager from the command line has this basic form:

npx @electron/packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]

This will:

  • Find or download the correct release of Electron
  • Use that version of Electron to create an app in <out>/<appname>-<platform>-<arch> (this can be customized via an optional flag)

--platform and --arch can be omitted, in two cases:

  • If you specify --all instead, bundles for all valid combinations of target platforms/architectures will be created.
  • Otherwise, a single bundle for the host platform/architecture 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)".

Example

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 locally
  • productName in package.json has been set to Foo Bar
  • The electron 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 once

When one runs the following command for the first time in the foobar directory:

npx @electron/packager .

@electron/packager will do the following:

  • Use the current directory for the sourcedir
  • Infer the appname from the productName in package.json
  • Infer the appVersion from the version in package.json
  • Infer the platform and arch from the host, in this example, darwin platform and arm64 arch.
  • Download the darwin arm64 build of Electron 38.3.0 (and cache the downloads in ~/.electron)
  • Build the macOS Foo Bar.app
  • Place Foo 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.

Related

  • Electron Forge - creates, builds, and distributes modern Electron applications

Distributable Creators

Windows:

macOS:

Linux:

Plugins

These Node modules utilize Electron Packager API hooks:

Footnotes

  1. 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

  2. Note for macOS / Mac App Store target bundles: the .app bundle can only be signed when building on a host macOS platform. ↩