Skip to content

fix: resolve circular sibling imports causing runtime ReferenceError#22752

Merged
kitlangton merged 1 commit intodevfrom
kit/ns-fix
Apr 16, 2026
Merged

fix: resolve circular sibling imports causing runtime ReferenceError#22752
kitlangton merged 1 commit intodevfrom
kit/ns-fix

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

Fix ReferenceError: Cannot access 'logger' before initialization caused by circular imports through barrel files.

When sibling files in the same directory import through their own index.ts barrel (e.g. observability.ts importing EffectLogger from "."), the module evaluation order can cause values to be accessed before they're initialized.

Fix

Changed all sibling-to-sibling imports to go directly to the source file instead of through the barrel:

// BEFORE (circular through barrel)
import { EffectLogger } from "."

// AFTER (direct)
import * as EffectLogger from "./logger"

23 files across effect/, config/, project/, lsp/, session/, share/, util/, provider/.

Root cause

The namespace migration changed import { X } from "./sibling" to import { X } from "." for sibling files. This created circular import chains since index.ts re-exports all siblings. Module-scope expressions that accessed the imported values (like EffectLogger.logger in a Logger.layer() call) crashed because the dependency hadn't finished evaluating yet.

EffectLogger.logger was accessed at module scope in observability.ts
before it finished initializing — caused by importing through the
barrel (index.ts) instead of directly from the sibling file.

Fixed the same pattern across all directories: sibling files that
import through their own barrel now import directly from the source.
@kitlangton kitlangton merged commit 0e20382 into dev Apr 16, 2026
8 checks passed
@kitlangton kitlangton deleted the kit/ns-fix branch April 16, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant