From 139cd337a3f8eea19faec0eaf0de67a0828ce072 Mon Sep 17 00:00:00 2001 From: backryun Date: Mon, 13 Apr 2026 09:26:35 +0900 Subject: [PATCH] [codex] Fix Electron server node path resolution (#1172) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integrated into release/v3.6.5 — fixes Windows Electron packaged startup failure caused by split NODE_PATH between app.asar.unpacked and app/node_modules. Review improvement: added debug log for skipped candidate paths. --- electron/main.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/electron/main.js b/electron/main.js index ac2c8fa7e7..acf0b94e5f 100644 --- a/electron/main.js +++ b/electron/main.js @@ -71,6 +71,37 @@ function resolveNodeExecutable(env = process.env) { return process.execPath; } +function resolveServerNodePath(env = process.env) { + const seen = new Set(); + const entries = []; + + const addEntry = (entry) => { + if (!entry || typeof entry !== "string") return; + const trimmed = entry.trim(); + if (!trimmed) return; + const normalized = path.normalize(trimmed); + if (seen.has(normalized)) return; // already included + if (!fs.existsSync(normalized)) { + console.debug("[Electron] NODE_PATH candidate not found (skipped):", normalized); + return; + } + seen.add(normalized); + entries.push(normalized); + }; + + for (const existing of (env.NODE_PATH || "").split(path.delimiter)) { + addEntry(existing); + } + + // Electron-builder installs native modules like better-sqlite3 under + // app.asar.unpacked, while the standalone bundle still carries helper deps + // such as bindings/file-uri-to-path inside resources/app/node_modules. + addEntry(path.join(process.resourcesPath, "app.asar.unpacked", "node_modules")); + addEntry(path.join(NEXT_SERVER_PATH, "node_modules")); + + return entries.join(path.delimiter); +} + function resolveDataDir(overridePath, env = process.env) { if (overridePath && overridePath.trim()) return path.resolve(overridePath); @@ -538,7 +569,7 @@ function startNextServer() { PORT: String(serverPort), NODE_ENV: "production", ELECTRON_RUN_AS_NODE: "1", - NODE_PATH: path.join(process.resourcesPath, "app.asar.unpacked", "node_modules"), + NODE_PATH: resolveServerNodePath(serverEnv), }, stdio: "pipe", });