#18524 · @sjawhar · opened Mar 21, 2026 at 1:32 PM UTC · last updated Mar 21, 2026 at 1:34 PM UTC
fix(bundler): rewrite namespace re-exports for Bun bundler compatibility
Score breakdown
Impact
Clarity
Urgency
Ease Of Review
Guidelines
Readiness
Size
Trust
Traction
Summary
This PR addresses a critical crash in the Bun-bundled binary caused by namespace re-exports evaluating to undefined. It rewrites 9 facade files to separate value and type exports, ensuring correct module initialization order for Bun's bundler. The fix preserves the identical public API surface and resolves a blocker for Bun users.
Description
Issue for this PR
Closes #18525
Type of change
- [x] Bug fix
- [ ] New feature
- [ ] Refactor / code improvement
- [ ] Documentation
What does this PR do?
Rewrites 9 facade/index files that re-export values from service modules inside TypeScript namespaces. Bun's bundler transpiles namespace re-exports like export const FileDiff = S.FileDiff into self-referential assignments (Snapshot.FileDiff = Snapshot.FileDiff) which evaluate to undefined when circular imports delay module initialization.
The fix splits each file into:
- A plain
export const X = { ... }object literal with value exports (eagerly initialized with correct references) - A separate
export namespace X { ... }block with type-only exports (erased at runtime)
This preserves the identical public API surface while ensuring Bun's bundler emits correct initialization code regardless of module evaluation order.
Files changed: src/snapshot/index.ts, src/question/index.ts, src/provider/auth.ts, src/file/index.ts, src/file/time.ts, src/skill/skill.ts, src/tool/truncate.ts, src/permission/index.ts, src/format/index.ts
How did you verify your code works?
bun typecheck— passes clean (tsgo --noEmit)bun run build --single— builds successfully- Bundled binary
opencode serve— starts and listens without TypeError (previously crashed withSnapshot2.FileDiff.arrayandProviderAuth2.Authorization.optionalerrors) - Bundled binary
opencode run "echo test"— creates session, runs LLM prompt loop, executes tools successfully
Screenshots / recordings
N/A — not a UI change.
Checklist
- [x] I have tested my changes locally
- [x] I have not included unrelated changes in this PR
Linked Issues
#18525 Bundled binary crashes with TypeError on namespace re-exports
View issueComments
No comments.
Changed Files
packages/opencode/src/file/index.ts
+34−31packages/opencode/src/file/time.ts
+24−19packages/opencode/src/format/index.ts
+13−11packages/opencode/src/permission/index.ts
+44−45packages/opencode/src/provider/auth.ts
+42−40packages/opencode/src/question/index.ts
+40−40packages/opencode/src/skill/skill.ts
+29−26packages/opencode/src/snapshot/index.ts
+40−33packages/opencode/src/tool/truncate.ts
+14−12