Skip to content

[Bug] Linux only - vite-plugin-electron kills esbuild when restarting electron #284

@djomlastic

Description

@djomlastic

Description

When executing ps command while restarting electron on Linux, Node process id is used to collect child process ids. That results in killing not only electron, but also it's siblings - esbuild.

Minimal reproduction

Use vanilla, typescript.

npm create vite@latest
npm i
npm i -D electron vite-plugin-electron vite-plugin-electron-renderer

Complete steps 2, 3 and 4 from vite-plugin-electron "Quick setup".

Edit electron/main.ts to log process ids:

console.log(`Electron pid: ${process.pid}`);
console.log(`Node pid: ${process.ppid}`);

Run the dev scirpt, use logged Node pid to list child processes (77334 in my example).

ps --ppid 77334
PID TTY          TIME CMD
  77341 pts/1    00:00:00 esbuild
  77352 pts/1    00:00:00 electron

Now edit electron/main.ts to trigger restart.

List node child processes again.

ps --ppid 77334
    PID TTY          TIME CMD
  77706 pts/1    00:00:00 electron

🪓 esbuild killed

After this, electron/main.ts is not rebuilt any more, editing src/main.ts will throw [plugin:vite:esbuild] The service is no longer running.

Fix

pidTree within src/utils.ts needs to pass electron's pid to ps command:

// pass tree.pid instead of tree.ppid
: `ps -o pid --no-headers --ppid ${tree.ppid}` // Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions