Skip to content

Fix Linux build and packaging for Node.js v22#225

Open
JesperGravgaard wants to merge 2 commits intonurpax:masterfrom
JesperGravgaard:fix-linux-build-node22
Open

Fix Linux build and packaging for Node.js v22#225
JesperGravgaard wants to merge 2 commits intonurpax:masterfrom
JesperGravgaard:fix-linux-build-node22

Conversation

@JesperGravgaard
Copy link
Copy Markdown

@JesperGravgaard JesperGravgaard commented Mar 8, 2026

Problem

Building and packaging Petmate as a .deb on modern Linux (Node.js v17+, Ubuntu 22.04+) is broken in several ways that together prevent the package from being built or from working correctly after installation.

Solution

package.json

electron-builder upgraded from v22 to v26.8.1
Version 22 is incompatible with Node.js 22 and fails at packaging time. v26.8.1 resolves this.

NODE_OPTIONS=--openssl-legacy-provider baked into the build and start scripts
Webpack (used internally by react-scripts) requires this flag on Node.js v17+ due to OpenSSL API changes. However, setting it globally causes Electron itself to crash on startup with an unrecognized option error. The fix scopes it only to the react-scripts process in both scripts, so npm run build and npm start work out of the box without any manual environment setup.

yarn replaced with npx
The start and debug scripts previously invoked yarn react-scripts, which fails if yarn is not installed. Replaced with npx react-scripts, which works with npm alone.

executableArgs: ["--no-sandbox"] added to linux build config
On Linux systems where the Chrome sandbox setuid binary is not configured (common in many environments), Electron refuses to start without --no-sandbox. This flag is added to executableArgs so it is written into the .desktop file, fixing launches from the application menu.

deb.afterInstall pointing to build-scripts/afterInstall.sh
See below.

@types/ms pinned to 0.7.34
The latest version (2.1.0) uses TypeScript 4 template literal types, which are incompatible with this project's TypeScript 3 compiler. This caused the build to fail with a type error in a transitive dependency. Pinning to 0.7.34 restores compatibility.

build-scripts/afterInstall.sh

electron-builder installs /usr/bin/petmate as a symlink pointing at the Electron binary in /opt/Petmate/petmate. Symlinks have no mechanism to inject command-line flags, so the --no-sandbox flag from executableArgs is not applied when launching from the terminal.

This postinst script runs after dpkg -i and replaces the symlink with a small shell wrapper:

#!/bin/sh
exec /opt/Petmate/petmate --no-sandbox "$@"

This ensures that running petmate from the terminal works without requiring the user to manually pass any flags.

README.md

Added a Linux section documenting how to build and package Petmate as a .deb. Covers system dependencies (fakeroot and dpkg-dev, required by electron-builder to produce a .deb), installing Node dependencies, running in development mode, and packaging and installing the .deb.

package-lock.json

Updated to reflect dependency changes.

Jesper Gravgaard added 2 commits March 8, 2026 09:37
- Replace yarn with npm/npx in start/debug scripts
- Scope NODE_OPTIONS=--openssl-legacy-provider to react-scripts only
  (Electron rejects it if set globally)
- Pass --no-sandbox to Electron (Chrome sandbox not configured on this system)
- Upgrade electron-builder from v22 to v26.8.1 (v22 incompatible with Node 22)
- Pin @types/ms to 0.7.34 (v2.1.0 uses TS4 template literals, project uses TS3)
- Set deb as the only Linux target (AppImage requires libfuse2, not available)
- Add executableArgs: [--no-sandbox] to linux build config (fixes app menu launch)
- Add build-scripts/afterInstall.sh: replaces /usr/bin/petmate symlink with a
  wrapper script that passes --no-sandbox, so CLI launch works without flags
- Update README with Linux build/run/package instructions
- Add system dependencies (fakeroot, dpkg-dev) to README
- Bake NODE_OPTIONS=--openssl-legacy-provider into the build script
  so plain 'npm run build' works without manual env var setup
- Fix hardcoded version in README install example to use a glob
- Rename 'Install dependencies' section to 'Install Node dependencies'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant