fix: pass electron version explicitly to electron-rebuild on Windows (#622)

Issue:
On Windows, running `npm run install:all` failed during the frontend
postinstall step. The electron-rebuild command couldn't auto-detect
Electron's version, failing with: "Unable to find electron's version
number, either install it or specify an explicit version"

Solution:
Added a `getElectronVersion()` helper function that reads the Electron
version from package.json's devDependencies and passes it explicitly
to electron-rebuild via the `-v` flag. This ensures the rebuild works
correctly even when version auto-detection fails.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Andy <119136210+AndyMik90@users.noreply.github.com>
This commit is contained in:
Vinícius Santos
2026-01-03 14:03:56 +02:00
committed by GitHub
parent 6c855905cb
commit 14b3db56fa
+24 -1
View File
@@ -42,13 +42,36 @@ To install:
================================================================================
`;
/**
* Get electron version from package.json
*/
function getElectronVersion() {
const pkgPath = path.join(__dirname, '..', 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const electronVersion = pkg.devDependencies?.electron || pkg.dependencies?.electron;
if (!electronVersion) {
return null;
}
// Strip leading ^ or ~ from version
return electronVersion.replace(/^[\^~]/, '');
}
/**
* Run electron-rebuild
*/
function runElectronRebuild() {
return new Promise((resolve, reject) => {
const npx = isWindows ? 'npx.cmd' : 'npx';
const child = spawn(npx, ['electron-rebuild'], {
const electronVersion = getElectronVersion();
const args = ['electron-rebuild'];
// Explicitly pass electron version if detected
if (electronVersion) {
args.push('-v', electronVersion);
console.log(`[postinstall] Using Electron version: ${electronVersion}`);
}
const child = spawn(npx, args, {
stdio: 'inherit',
shell: isWindows,
cwd: path.join(__dirname, '..'),