Skip to content

Bundled binary crashes with TypeError on namespace re-exports #18525

@sjawhar

Description

@sjawhar

Bug description

The Bun-bundled binary crashes at startup with errors like:

TypeError: undefined is not an object (evaluating 'Snapshot2.FileDiff.array')
TypeError: undefined is not an object (evaluating 'ProviderAuth2.Authorization.optional')

Root cause

Nine facade files (e.g. src/snapshot/index.ts, src/provider/auth.ts) re-export values from a service module inside a TypeScript namespace:

import { Snapshot as S } from "./service"
export namespace Snapshot {
  export const FileDiff = S.FileDiff
}

Bun's bundler transpiles this into self-referential assignments (Snapshot.FileDiff = Snapshot.FileDiff). When circular imports delay module initialization, the right-hand side is undefined.

Steps to reproduce

  1. Introduce any circular dependency chain that passes through one of these facade modules
  2. Build with bun run build --single
  3. Run the binary — crashes before startup completes

Expected behavior

Binary starts without TypeError.

Environment

  • Bun 1.3.10
  • opencode built with --single flag

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions