All posts

Fix MemoryError in Electron When Deploying

Resolve memory errors when building and packaging Electron apps, covering electron-builder memory limits and native module compilation.

Electron Build Memory Errors

Electron app packaging — using electron-builder, electron-forge, or electron-packager — is resource-intensive. Bundling Chromium with your app, compiling native modules, and creating installers can exhaust memory.

Node.js Heap During Build

The electron-builder process itself can run out of memory:

{
  "scripts": {
    "build": "node --max-old-space-size=8192 node_modules/.bin/electron-builder"
  }
}

ASAR Archive Size

Electron packs your source into an ASAR archive. If node_modules is huge, this step consumes enormous memory:

{
  "build": {
    "asar": true,
    "asarUnpack": [
      "node_modules/sharp/**/*",
      "**/*.node"
    ],
    "files": [
      "dist/**/*",
      "!node_modules/.cache"
    ]
  }
}

Exclude development dependencies:

npm prune --production

Native Module Compilation

Modules like better-sqlite3 or sharp are rebuilt for Electron. This uses significant memory:

# Pre-build native modules
npx electron-rebuild --force

CI Configuration

# GitHub Actions
jobs:
  build-electron:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
    env:
      NODE_OPTIONS: --max-old-space-size=8192
    steps:
      - run: npm run build

Allocate at least 8GB RAM for the build runner when targeting all platforms.

Bugsly captures build failure events from your CI pipeline via webhook integrations, grouping memory-related failures separately from test failures.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free