From e565d873f918424c1904c77bca06ddb3045473f9 Mon Sep 17 00:00:00 2001 From: 7418 <7418@openclaw.ai> Date: Fri, 6 Feb 2026 22:40:24 +0800 Subject: [PATCH] fix: use Electron's Node.js for standalone server to match ABI electron-builder's @electron/rebuild compiles better-sqlite3 for Electron's Node ABI. The standalone server must use Electron's built-in Node (ELECTRON_RUN_AS_NODE=1) to match, otherwise the native module fails with NODE_MODULE_VERSION mismatch. Co-Authored-By: Claude Opus 4.6 --- electron/main.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 6bde243..0110f2b 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -94,8 +94,11 @@ async function waitForServer(port: number, timeout = 30000): Promise { function startServer(port: number): ChildProcess { const standaloneDir = path.join(process.resourcesPath, 'standalone'); const serverPath = path.join(standaloneDir, 'server.js'); - const nodePath = findNodePath(); - const useElectronAsNode = nodePath === process.execPath; + + // Always use Electron's built-in Node.js in packaged mode. + // electron-builder's @electron/rebuild compiles native modules (better-sqlite3) + // for Electron's Node ABI, so we must use the matching runtime. + const nodePath = process.execPath; console.log(`Using Node.js: ${nodePath}`); console.log(`Server path: ${serverPath}`); @@ -108,13 +111,10 @@ function startServer(port: number): ChildProcess { PORT: String(port), HOSTNAME: '127.0.0.1', CLAUDE_GUI_DATA_DIR: app.getPath('userData'), + ELECTRON_RUN_AS_NODE: '1', PATH: `/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:${process.env.PATH || ''}`, }; - if (useElectronAsNode) { - env.ELECTRON_RUN_AS_NODE = '1'; - } - const child = spawn(nodePath, [serverPath], { env, stdio: 'pipe',