-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(utils): runtime require('./initStorage') fails in bundled output #1599
Description
Description
copyFilesToDirectory throws Cannot find module './initStorage' at runtime after PR #1583 refactoring, breaking ACP conversations on the second message send.
Root Cause
PR #1583 changed a static import to a lazy require('./initStorage') in src/process/utils/utils.ts to break a circular dependency. However, Vite/Rollup does not transform dynamic require() relative paths — the bundled output resolves ./initStorage relative to the chunk file in out/main/chunks/, where no such module exists.
The bug only manifests when files parameter is not undefined (e.g., [] empty array), because copyFilesToDirectory short-circuits with if (!files) return [] before reaching the broken require.
- First message from guid page:
files: undefined→ skipped → works - Second message from SendBox:
files: []→![]is false → hitsrequire('./initStorage')→ crash
Fix
Replace require('./initStorage') with a static import. The circular dependency is safe because getSystemDir is only called at runtime inside function bodies, not during module initialization.