Skip to content

fix(utils): runtime require('./initStorage') fails in bundled output #1599

@kaizhou-lab

Description

@kaizhou-lab

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 → hits require('./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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions