Skip to content

Fix sqlite-vector ESM module resolution with platform-specific packages#492

Merged
sroussey merged 1 commit into
mainfrom
claude/add-sqlite-vector-test-tKxND
May 12, 2026
Merged

Fix sqlite-vector ESM module resolution with platform-specific packages#492
sroussey merged 1 commit into
mainfrom
claude/add-sqlite-vector-test-tKxND

Conversation

@sroussey
Copy link
Copy Markdown
Collaborator

Summary

Fixes module resolution issues with @sqliteai/sqlite-vector in ESM contexts by switching from dynamic import() to CommonJS require() via createRequire(). This ensures platform-specific sub-packages (darwin-arm64, linux-x86_64, etc.) resolve correctly.

Changes

  • package.json: Added optional dependencies for all platform-specific sqlite-vector variants (darwin-arm64, darwin-x86_64, linux-arm64, linux-arm64-musl, linux-x86_64, linux-x86_64-musl, win32-x86_64) and added @sqliteai/sqlite-vector to devDependencies in both root and test packages using catalog references
  • SqliteAiVectorStorage.ts: Replaced dynamic import("@sqliteai/sqlite-vector") with createRequire(import.meta.url) to properly resolve platform-specific sub-packages in ESM contexts
  • SqliteAiVectorStorage.ts: Fixed potential integer overflow in topK parameter by applying bitwise OR with 0 (topK | 0) to ensure it's treated as a 32-bit integer
  • SqliteAiVectorStorage.integration.test.ts: Updated test setup to use createRequire() instead of dynamic import for consistent module resolution and added await Sqlite.init() call before database operations

Implementation Details

The core issue was that ESM's dynamic import() doesn't properly resolve the conditional exports that sqlite-vector uses to load platform-specific native bindings. By using CommonJS require() via createRequire(), the module resolution falls back to Node's standard package resolution algorithm, which correctly handles the platform-specific sub-package selection.

The optional dependencies declaration ensures all platform variants are available during installation, allowing the correct one to be selected at runtime based on the current platform.

https://claude.ai/code/session_01N1fkmMs9nv3rooEjrwuLQ9

…ading

- Add @sqliteai/sqlite-vector devDependency to packages/test
- Add all platform-specific sqlite-vector packages as root optionalDependencies
  so bun installs the correct binary on each platform
- Fix SqliteAiVectorStorage to use createRequire (CJS) instead of dynamic ESM
  import for loading the extension, since the package's ESM build uses a
  __require shim that silently fails in true ESM environments (vitest/Node ESM)
- Fix test availability check similarly with createRequire + Sqlite.init()
- Fix topK cast to integer for vector_full_scan (was passing REAL)

https://claude.ai/code/session_01N1fkmMs9nv3rooEjrwuLQ9
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

@workglow/cli

npm i https://pkg.pr.new/@workglow/cli@492

@workglow/ai

npm i https://pkg.pr.new/@workglow/ai@492

@workglow/job-queue

npm i https://pkg.pr.new/@workglow/job-queue@492

@workglow/knowledge-base

npm i https://pkg.pr.new/@workglow/knowledge-base@492

@workglow/storage

npm i https://pkg.pr.new/@workglow/storage@492

@workglow/task-graph

npm i https://pkg.pr.new/@workglow/task-graph@492

@workglow/tasks

npm i https://pkg.pr.new/@workglow/tasks@492

@workglow/util

npm i https://pkg.pr.new/@workglow/util@492

workglow

npm i https://pkg.pr.new/workglow@492

commit: 7b45be9

@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 62.8% 20650 / 32877
🔵 Statements 62.66% 21372 / 34106
🔵 Functions 65.15% 3974 / 6099
🔵 Branches 51.9% 9943 / 19156
File CoverageNo changed files found.
Generated in workflow #2215 for commit 7b45be9 by the Vitest Coverage Report Action

@sroussey sroussey merged commit 0dd02be into main May 12, 2026
22 checks passed
@sroussey sroussey deleted the claude/add-sqlite-vector-test-tKxND branch May 12, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants