fix(utils): replace runtime require with static import for initStorage#1600
Merged
fix(utils): replace runtime require with static import for initStorage#1600
Conversation
The refactoring in PR #1583 changed `import { getSystemDir } from './initStorage'` to a lazy `require('./initStorage')` to break a circular dependency. However, Vite/Rollup does not transform dynamic `require()` relative paths in bundled output, causing `copyFilesToDirectory` to throw "Cannot find module './initStorage'" at runtime when `files` is a non-empty or empty array (not undefined). This broke the second message in ACP conversations because the first message passes `files: undefined` (skipping the require), while subsequent messages pass `files: []` (empty array), which reaches the broken require call. Replace `require('./initStorage')` with a static import. The circular dependency between utils.ts and initStorage.ts is safe because `getSystemDir` is only called at runtime inside function bodies, not during module initialization. This matches the pre-refactor behavior that worked correctly.
piorpua
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cannot find module './initStorage'crash incopyFilesToDirectoryafter PR refactor: reorganize src/ directory structure (835 files, 0 TS errors) #1583 refactoringrequire('./initStorage')with staticimport— Vite does not transform runtimerequire()relative paths in bundled outputChanges
src/process/utils/utils.ts: RemovelazyGetSystemDir()wrapper usingrequire('./initStorage'), replace with staticimport { getSystemDir } from './initStorage'Root Cause
PR #1583 changed a static import to a lazy
require()to break circular dependency. In bundled output,require('./initStorage')resolves relative toout/main/chunks/, where no such module exists. The bug only triggers whenfilesis[](empty array, notundefined), which is why the first message from guid page works but subsequent messages fail.Related Issue
Closes #1599
Test Plan