Electron Snap Installer

raw JSON →
5.2.0 verified Sat Apr 25 auth: no javascript

Builds Snap packages for Electron applications that have already been bundled with electron-packager. Current stable version is 5.2.0, released in 2021 with dependency reductions, TypeScript definitions, and a default confinement change from classic to strict. Requires Node 10+ and snapcraft. Key differentiators: integrates with Electron Forge, autodetects base snap option, and handles Electron sandbox features for Snap confinement.

error Error: spawn snapcraft ENOENT
cause snapcraft is not installed or not in PATH
fix
Install snapcraft: sudo snap install snapcraft --classic
error Error: Invalid snap name: my.app (invalid characters)
cause Snap names must be lowercase alphanumeric with hyphens
fix
Ensure the 'name' option uses only [a-z0-9-]
error TypeError: installer is not a function
cause Using CommonJS require on an ESM-only module
fix
Use import or dynamic import: const installer = (await import('electron-installer-snap')).default
error Error: The 'src' directory does not exist: /path/to/nonexistent
cause Specified src path is incorrect or missing
fix
Run electron-packager first and provide the correct output directory
breaking The default confinement has changed from 'classic' to 'strict' in v5.2.0.
fix Explicitly set confinement to 'classic' if your app requires classic confinement, or adjust your app to work under strict confinement.
breaking Callback-style support was removed in v4.0.0.
fix Use async/await or util.callbackify() to convert the promise-based API.
gotcha Node.js 10 is the minimum required version; Node.js 8 support was dropped in v5.0.0.
fix Ensure your Node.js version is >= 10.
deprecated The 'snapcraft' command-line tool must be installed separately and may not be in PATH.
fix Install snapcraft (e.g., 'sudo snap install snapcraft --classic') and ensure it's available, or specify its path via the 'snapcraft' option.
gotcha EINVAL errors often occur when the 'src' path points to an invalid or incomplete Electron app directory.
fix Verify that 'src' contains the full electron-packager output (with app binary, resources, etc.).
gotcha Snap builds may fail if the 'base' option is not set correctly for your Electron version.
fix Set the 'base' option (e.g., 'core18', 'core20') explicitly or rely on autodetection; check snapcraft requirements.
npm install electron-installer-snap
yarn add electron-installer-snap
pnpm add electron-installer-snap

Shows how to use the JavaScript API with async/await to create a Snap package from an electron-packager output directory.

import installer from 'electron-installer-snap';

const options = {
  src: 'out/myappname-linux-x64',
  dest: 'dist/',
  arch: 'amd64',
  name: 'myapp',
  productName: 'My App',
  version: '1.0.0',
  description: 'My Electron App',
  summary: 'A snap of My App',
  license: 'Apache-2.0',
  base: 'core18',
  confinement: 'strict',
  grade: 'stable',
  assumes: ['snapd2.43'],
  plugs: ['home', 'x11', 'wayland', 'unity7', 'pulseaudio', 'opengl'],
  slots: [],
  stages: ['-usr/share/man'],
  after: [],
  electronVersion: '11.0.0',
  snapcraft: '/snap/bin/snapcraft',
  template: '/path/to/template.snapcraft.yaml',
};

async function buildSnap() {
  try {
    await installer(options);
    console.log('Snap package created successfully');
  } catch (err) {
    console.error('Snap creation failed:', err);
  }
}

buildSnap();