Skip to content

Broken imports #30651

Closed
Closed

Description

@sroussey

What version of Bun is running?

1.3.14+0d9b296af

What platform is your computer?

Linux 6.19.13-orbstack-gbd1dc07b8cf4 aarch64 unknown

What steps can reproduce the bug?

git clone https://github.com/workglow-dev/libs.git
cd libs
bun install
bun run build
bun run test:bun:ai-provider-llamacpp

What is the expected behavior?

The tests should run rather than fail. They are correct in node and in the previous version of bun (1.3.13)

What do you see instead?

Cannot access 'isCI' before initialization. (transpiler issue i guess, the file has a definition after exporting something with await, so maybe a top level await issue?)

packages/test/src/test/ai-provider/LlamaCpp_ChatWrapper.integration.test.ts:
PermanentJobError: Provider LOCAL_LLAMACPP failed for ModelDownloadTask: Cannot access 'isCI' before initialization.

--- Error diagnostics ---
ReferenceError: Cannot access 'isCI' before initialization.
ReferenceError: Cannot access 'isCI' before initialization.
at _init (/workspaces/workglow/libs/node_modules/.bun/node-llama-cpp@3.18.1+7524df1edfed9f02/node_modules/node-llama-cpp/dist/utils/createModelDownloader.js:284:27)
at async _create (/workspaces/workglow/libs/node_modules/.bun/node-llama-cpp@3.18.1+7524df1edfed9f02/node_modules/node-llama-cpp/dist/utils/createModelDownloader.js:366:31)
at async (/workspaces/workglow/libs/providers/node-llama-cpp/dist/ai-runtime.js:368:28)
at async execute (/workspaces/workglow/libs/packages/ai/src/job/AiJob.ts:278:13)
at async execute (/workspaces/workglow/libs/packages/ai/src/execution/QueuedExecutionStrategy.ts:59:17)
at async execute (/workspaces/workglow/libs/packages/ai/src/task/base/AiTask.ts:165:20)
at async executeTask (/workspaces/workglow/libs/packages/task-graph/src/task/TaskRunner.ts:480:36)
at async run (/workspaces/workglow/libs/packages/task-graph/src/task/TaskRunner.ts:214:26)
at processTicksAndRejections (native:7:39)

Additional information

the source from node-llama-cpp:
https://github.com/withcatai/node-llama-cpp/blob/57bea3da9ffa78955e8b25f195ce6cc714980cb5/src/config.ts#L43-L47

Activity

  1. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    Found 2 possible duplicate issues:

    1. [1.3.14] ESM TDZ error when importing Lexical React modules that re-export through top-level await #30634
    2. regression: when importing a module with top-level await multiple times, all but the first import throw ReferenceError #30259

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. robobun commented on May 14, 2026

    @robobun
    Collaborator

    ✅ Fixed on main via #32437 (merged).

    The parallel-dynamic-import TDZ bug (ReferenceError: Cannot access "..." before initialization when two dynamic import()s share a still-suspended top-level-await dependency, as in node-llama-cpp) now resolves correctly. Verified on current main:

    $ bun driver.mjs   # two parallel dynamic imports of a shared TLA dep
    entry1 foo: 123
    entry2 foo: 123
    

    test/js/bun/resolve/dynamic-import-tla-cycle.test.ts passes 6/6, including the sibling dynamic imports sharing a TLA wrapper wait for its post-await exports regression test.

    #32437 threads the referrer module's asyncEvaluationOrder through to JSC (via JSModuleLoader::asyncEvaluationOrderForKey()) so the TLA self-deadlock skip only fires for the genuine Nitro self-deadlock, not for unrelated parallel dynamic imports. It supersedes the earlier attempt in #30656. The fix ships in the next release / latest canary.

  3. sroussey commented on May 14, 2026

    @sroussey
    ContributorAuthor

    Just a note that this is a regression in 1.3.14, this does not exist in 1.3.13 nor node 20/22/24

  4. robobun commented on Jul 24, 2026

    @robobun
    Collaborator

    Fixed by #32437.

    Verified on main at df84f8d: parallel dynamic imports that share a top-level-await dependency (the node-llama-cpp config.ts → isCI pattern) now wait for the post-await bindings instead of hitting TDZ.

    # wrapper.mjs: const mod = await import("./inner.mjs"); export const FOO = mod.FOO; ...
    # entry.mjs:   await Promise.all([import("./consumer1.mjs"), import("./consumer2.mjs")])
    $ bun-df84f8d entry.mjs
    foo bar
    

    vs 1.3.14+0d9b296af:

    ReferenceError: Cannot access 'wrapped' before initialization.
        at consumer2.mjs:2:20
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions