From aceeedb3665b77acafa3985099498b74b35742d8 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Tue, 3 Mar 2026 19:47:23 -0800 Subject: [PATCH] fix: resolve circular import crash in rnotes converters Bun evaluates the converters Map after the circular import from obsidian.ts triggers registerConverter(), causing "Cannot access before initialization". Lazy-load converter modules via require() to break the cycle. Co-Authored-By: Claude Opus 4.6 --- modules/rnotes/converters/index.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/rnotes/converters/index.ts b/modules/rnotes/converters/index.ts index 769b40b..f95e731 100644 --- a/modules/rnotes/converters/index.ts +++ b/modules/rnotes/converters/index.ts @@ -73,16 +73,26 @@ export function registerConverter(converter: NoteConverter): void { } export function getConverter(id: string): NoteConverter | undefined { + ensureConvertersLoaded(); return converters.get(id); } export function getAllConverters(): NoteConverter[] { + ensureConvertersLoaded(); return Array.from(converters.values()); } -// ── Import converters on module load ── -// These register themselves when imported -import './obsidian'; -import './logseq'; -import './notion'; -import './google-docs'; +// ── Lazy-load converters to avoid circular init ── +// Each converter imports registerConverter from this file; importing them +// synchronously at the module level causes a "Cannot access before +// initialization" error in Bun because the converters Map hasn't been +// assigned yet when the circular import triggers registerConverter(). +let _loaded = false; +export function ensureConvertersLoaded(): void { + if (_loaded) return; + _loaded = true; + require('./obsidian'); + require('./logseq'); + require('./notion'); + require('./google-docs'); +}