fix(electron): name the exe to start for a wrong Windows executablePath
What
On Windows, electron({ executablePath }) is checked to be a program before the run starts, and the error names the file to use instead:
executablePath names | Error ends with |
|---|---|
a shortcut (.lnk) | it is a shortcut: name the .exe it points to |
| the app's folder | name the app's .exe inside the folder (it holds MyApp.exe, Uninstall MyApp.exe) |
a path without .exe | name the file with its extension, C:\...\MyApp.exe |
a Squirrel launcher (MyApp.exe beside Update.exe) | name the app itself, C:\...\app-3.7.1\MyApp.exe |
e2e doctor reports the same. The docs page gets a Windows example for a packaged app.
Why
Found while driving installed apps on a Windows Server 2025 machine. Windows has no execute bit, so the check accepted any readable file:
- A desktop shortcut passed the check and
e2e doctor, then failed every test withcould not launch ...lnk: spawn EFTYPE. - A folder or a path without
.exesaidnot an executable filewith no fix. macOS already gets one for a.appbundle. - GitHub Desktop, installed by Squirrel, has a
GitHubDesktop.exeat the install root that startsapp-3.7.1\GitHubDesktop.exeand exits. Every test failed withthe app quit before it opened a window (with exit code 0).
How it works
isExecutableFiletakes the platform. On Windows it reads the file's first two bytes and accepts a program image (MZ), which is whatCreateProcessstarts. Other platforms keep the execute-permission check.packages/electron/src/executable.ts:56squirrelApprecognizes a Squirrel launcher by its layout:Update.exebeside it, andapp-<version>folders that hold an exe of its name. With one version installed it returns that exe's path. With several it names the folders, since which one the launcher starts is Squirrel's rule and guessing it could name a stale build.executable.ts:96executableHintbuilds the hint for a path that is no executable: the.appbundle text as before, then on Windows the shortcut, the missing extension, and the folder. The last two go throughsquirrelApp, so they never point at a launcher.executable.ts:113locateExecutablerefuses a launcher that passed the image check.executable.ts:142resolveExecutableanddescribeExecutabletake an optional platform so the unit tests cover the Windows rules on any OS.
Not changed: an app execution alias (%LOCALAPPDATA%\Microsoft\WindowsApps\*.exe, Store installs) is refused on main too, because stat fails on it with EACCES.
Issue
None filed. Found in a Windows verification pass of @e2e-dev/electron.
Verified
Ran it locally: yes, on a Windows Server 2025 machine (interactive desktop session), with the testbed app packaged by electron-builder (NSIS) and installed, and GitHub Desktop 3.7.1 installed by its Squirrel installer.
e2e run with each executablePath:
executablePath | main | this PR |
|---|---|---|
...\Desktop\E2E Testbed App.lnk | 12 tests fail: could not launch ...lnk: spawn EFTYPE; doctor passes | config error: it is a shortcut: name the .exe it points to (its Target, under Properties) |
...\Programs\e2e-testbed-packaged | which is not an executable file | ...; name the app's .exe inside the folder (it holds E2E Testbed App.exe, Uninstall E2E Testbed App.exe) |
...\e2e-testbed-packaged\E2E Testbed App | which is not an executable file | ...; name the file with its extension, C:\...\E2E Testbed App.exe |
...\GitHubDesktop\GitHubDesktop.exe | test fails: the app quit before it opened a window (with exit code 0) | config error: the launcher its installer left there: it starts the app and exits, so name the app itself, C:\...\GitHubDesktop\app-3.7.1\GitHubDesktop.exe |
...\GitHubDesktop | which is not an executable file | ...; name the app's .exe, C:\...\GitHubDesktop\app-3.7.1\GitHubDesktop.exe |
...\e2e-testbed-packaged\E2E Testbed App.exe | 12 passed | 12 passed |
===== C:\Users\Administrator\Desktop\E2E Testbed App.lnk
electron({ executablePath }) names C:\Users\Administrator\Desktop\E2E Testbed App.lnk, which is not an executable file; it is a shortcut: name the .exe it points to (its Target, under Properties)
===== C:\Users\Administrator\AppData\Local\GitHubDesktop\GitHubDesktop.exe
electron({ executablePath }) names C:\Users\Administrator\AppData\Local\GitHubDesktop\GitHubDesktop.exe, the launcher its installer left there: it starts the app and exits, so name the app itself, C:\Users\Administrator\AppData\Local\GitHubDesktop\app-3.7.1\GitHubDesktop.exe
===== good
Tests 12 passed (12)
Unit tests on Windows and macOS: pnpm --filter @e2e-dev/electron test, 99 passed on both. pnpm check passes.
No terminal recording: the change is one error line, quoted above. No docs screenshot: the page gains one code block and one paragraph.