Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(electron): resolve main output root from inside Rollup chunks

mingkun968bf9a02a5bcdc
diff --git a/apps/desktop/electron/main/module-path.ts b/apps/desktop/electron/main/module-path.ts
index 7313c05a7..1a80f9336 100644
--- a/apps/desktop/electron/main/module-path.ts
+++ b/apps/desktop/electron/main/module-path.ts
@@ -1,7 +1,16 @@
-import { dirname } from "node:path";
+import { basename, dirname } from "node:path";
import { fileURLToPath } from "node:url";
-/** Resolve the filesystem directory for the current ES module URL. */
+/**
+ * Resolve the built Main output directory that owns `moduleUrl`.
+ *
+ * Rollup emits Main as `out/main/index.js` plus shared chunks under
+ * `out/main/chunks/`, so collapse the `chunks` segment instead of leaking
+ * the chunk nesting into runtime paths (renderer entry, preloads,
+ * plugin host). Without this the app loads a missing index.html (black screen).
+ */
export function getModuleDirectory(moduleUrl: string): string {
- return dirname(fileURLToPath(moduleUrl));
+ let directory = dirname(fileURLToPath(moduleUrl));
+ while (basename(directory) === "chunks") directory = dirname(directory);
+ return directory;
}