Skip to content

bug: circular deps error #602

@sroussey

Description

@sroussey

Issue description

ReferenceError: Cannot access 'isCI' before initialization.

Expected Behavior

node-llama-cpp’s dist/config.js has a circular dependency: config.js loads binariesGithubRelease.js, which imports back from config.js. While config.js is paused on await getBinariesGithubRelease(), another arm of the graph can load createModelDownloader.js, which imports isCI from config.js. In the published file, isCI was declared after that top-level await, so it was still in the temporal dead zone → ReferenceError: Cannot access 'isCI' before initialization.

Actual Behavior

ReferenceError: Cannot access 'isCI' before initialization.

Steps to reproduce

It is a timing error based on multiple vitest threads running tests in parallel

My Environment

Mac devcontainer, but also github actions

OS: Debian GNU/Linux 12 (bookworm) (arm64)
Node: 24.14.1 (arm64)

node-llama-cpp: 3.18.1
Prebuilt binaries: b8390

Vulkan: Vulkan is detected, but using it failed
To resolve errors related to Vulkan, see the Vulkan guide: https://node-llama-cpp.withcat.ai/guide/Vulkan

CPU model: unknown
Math cores: 12
Used RAM: 54.12% (12.71GB/23.49GB)
Free RAM: 45.87% (10.78GB/23.49GB)
Used swap: 9.02% (2.21GB/24.49GB)
Max swap size: 24.49GB
mmap: supported

Additional Context

https://github.com/workglow-dev/libs/actions/runs/25813888963/job/75837336404?pr=4941s
Run bun run test:bun:ai-provider-llamacpp
$ bun scripts/test.ts bun integration provider-llamacpp

Running integration tests in sections [provider-llamacpp] — 4 file(s)

bun test v1.3.14 (0d9b296a) 1x PARALLEL

packages/test/src/test/ai-provider/LlamaCpp_ChatWrapper.integration.test.ts:

packages/test/src/test/ai-provider/LlamaCpp_Generic.integration.test.ts:

packages/test/src/test/ai-provider/LlamaCpp_NativeToolCalling.integration.test.ts:

packages/test/src/test/ai-provider/LlamaCppProviderIntegration.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 (/home/runner/work/libs/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 (/home/runner/work/libs/libs/node_modules/.bun/node-llama-cpp@3.18.1+7524df1edfed9f02/node_modules/node-llama-cpp/dist/utils/createModelDownloader.js:366:31)
at async (/home/runner/work/libs/libs/providers/node-llama-cpp/dist/ai-runtime.js:368:28)
at async execute (/home/runner/work/libs/libs/packages/ai/src/job/AiJob.ts:278:13)
at async execute (/home/runner/work/libs/libs/packages/ai/src/execution/QueuedExecutionStrategy.ts:59:17)
at async execute (/home/runner/work/libs/libs/packages/ai/src/task/base/AiTask.ts:165:20)
at async executeTask (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:480:36)
at async run (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:214:26)
at async runTask (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:514:39)
at async runLoop (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/RunScheduler.ts:313:19)
at async runGraph (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:205:47)
at processTicksAndRejections (native:7:39)
PermanentJobError {
message: "Provider LOCAL_LLAMACPP failed for ModelDownloadTask: Cannot access 'isCI' before initialization.\n\n--- Error diagnostics ---\nReferenceError: Cannot access 'isCI' before initialization.\nReferenceError: Cannot access 'isCI' before initialization.\n at _init (/home/runner/work/libs/libs/node_modules/.bun/node-llama-cpp@3.18.1+7524df1edfed9f02/node_modules/node-llama-cpp/dist/utils/createModelDownloader.js:284:27)\n at async _create (/home/runner/work/libs/libs/node_modules/.bun/node-llama-cpp@3.18.1+7524df1edfed9f02/node_modules/node-llama-cpp/dist/utils/createModelDownloader.js:366:31)\n at async (/home/runner/work/libs/libs/providers/node-llama-cpp/dist/ai-runtime.js:368:28)\n at async execute (/home/runner/work/libs/libs/packages/ai/src/job/AiJob.ts:278:13)\n at async execute (/home/runner/work/libs/libs/packages/ai/src/execution/QueuedExecutionStrategy.ts:59:17)\n at async execute (/home/runner/work/libs/libs/packages/ai/src/task/base/AiTask.ts:165:20)\n at async executeTask (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:480:36)\n at async run (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:214:26)\n at async runTask (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:514:39)\n at async runLoop (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/RunScheduler.ts:313:19)\n at async runGraph (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:205:47)\n at processTicksAndRejections (native:7:39)",
name: "PermanentJobError",
stack: "Error\n at classifyProviderError (/home/runner/work/libs/libs/packages/ai/src/job/AiJob.ts:210:14)\n at execute (/home/runner/work/libs/libs/packages/ai/src/job/AiJob.ts:287:13)\n at async execute (/home/runner/work/libs/libs/packages/ai/src/execution/QueuedExecutionStrategy.ts:59:17)\n at async execute (/home/runner/work/libs/libs/packages/ai/src/task/base/AiTask.ts:165:20)\n at async executeTask (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:480:36)\n at async run (/home/runner/work/libs/libs/packages/task-graph/src/task/TaskRunner.ts:214:26)\n at async runTask (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:514:39)\n at async runLoop (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/RunScheduler.ts:313:19)\n at async runGraph (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/TaskGraphRunner.ts:205:47)\n at async run (/home/runner/work/libs/libs/packages/task-graph/src/task-graph/Workflow.ts:268:39)",
retryable: false,
toString: [Function: toString],
}

Relevant Features Used

  • Metal support
  • CUDA support
  • Vulkan support
  • Grammar
  • Function calling

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrequires triageRequires triaging

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions