-
Notifications
You must be signed in to change notification settings - Fork 576
Description
Bug
The Electron app crashes on startup with:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@automaker/platform' imported from .../server/index.js
Root Cause
prepare-server.mjs uses file: references for local @automaker/* packages in the server bundle's package.json. When npm install runs, it creates symlinks in node_modules/@automaker/ pointing to ../../libs/<pkg>. After electron-builder packages the app, these symlinks break because the relative targets no longer exist.
Additionally, electronUserDataWriteFileSync fails to write .api-key because the userData directory doesn't exist yet on first launch.
Fix
apps/ui/scripts/prepare-server.mjs — after npm install, replace symlinks with real directory copies:
// Step 6b: Replace symlinks for local packages with real copies
const nodeModulesAutomaker = join(BUNDLE_DIR, 'node_modules', '@automaker');
for (const pkgName of LOCAL_PACKAGES) {
const pkgDir = pkgName.replace('@automaker/', '');
const nmPkgPath = join(nodeModulesAutomaker, pkgDir);
if (existsSync(nmPkgPath) && lstatSync(nmPkgPath).isSymbolicLink()) {
const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir);
rmSync(nmPkgPath);
cpSync(realPath, nmPkgPath, { recursive: true });
}
}(Also add lstatSync and resolve to the fs/path imports.)
libs/platform/src/system-paths.ts — ensure parent directory exists before writing:
const fullPath = path.join(electronUserDataPath, relativePath);
const dir = path.dirname(fullPath);
if (!fsSync.existsSync(dir)) {
fsSync.mkdirSync(dir, { recursive: true });
}
fsSync.writeFileSync(fullPath, data, options);Verification
After applying both fixes, npm run build:electron:mac produces a working app that starts without errors.