Date: 2026-05-10
Severity: Critical (blocks all dev/build)
Area: Build / Dev Environment
Root Cause: Bun skipped Electron's postinstall script during bun install
Running bun run dev produced:
error during start dev server and electron app:
Error: Electron uninstall
at getElectronPath (file:///E:/project/node/nekocode/node_modules/electron-vite/dist/chunks/lib-ClgyQuZx.js:132:19)
at startElectron (file:///E:/project/node/nekocode/node_modules/electron-vite/dist/chunks/lib-ClgyQuZx.js:205:26)
The Vite renderer dev server started successfully on http://localhost:5173/, and both the main process and preload built without errors. The failure occurred only when electron-vite attempted to launch the Electron app process.
node_modules/electron/directory existed withpackage.json,index.js,install.js,checksums.json- Electron package version: 34.5.8
node_modules/electron/path.txt— does not existnode_modules/electron/dist/— does not exist
The node_modules/electron/index.js file contains:
const pathFile = path.join(__dirname, 'path.txt');
function getElectronPath () {
let executablePath;
if (fs.existsSync(pathFile)) {
executablePath = fs.readFileSync(pathFile, 'utf-8');
}
if (executablePath) {
return path.join(__dirname, 'dist', executablePath);
} else {
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
}
}The electron npm package is a wrapper — it does not contain the Electron binary itself. The actual binary (~190 MB electron.exe on Windows) is downloaded during the postinstall lifecycle hook (install.js). Bun, in certain configurations or versions, can skip postinstall scripts, leaving the wrapper package present but the binary absent.
electron-rebuild recompiles native Node addons (.node files) against Electron's Node headers. It has nothing to do with downloading the Electron binary itself. Running it reported "No native modules found" and completed without error, but the underlying binary absence remained.
Run the Electron install script directly:
node node_modules/electron/install.jsThis downloads the Electron v34.5.8 binary into node_modules/electron/dist/ and creates path.txt containing electron.exe.
# Should return True
Test-Path "node_modules/electron/path.txt"
Test-Path "node_modules/electron/dist"
# Should contain "electron.exe"
Get-Content "node_modules/electron/path.txt"
# Should list electron.exe + supporting files
Get-ChildItem "node_modules/electron/dist"After running bun install on a fresh clone or after rm -rf node_modules, always verify the Electron binary exists:
Test-Path "node_modules/electron/dist/electron.exe"If missing, run:
node node_modules/electron/install.jsAlternatively, consider adding a postinstall check to package.json or a setup script that ensures the Electron binary is present before dev/build commands execute.
- Blocked:
bun run dev(dev server + Electron launch) - Blocked: Any
electron-vitecommand that needs to spawn Electron - Not affected: Main process build, preload build, renderer Vite dev server, tests, linting