Fix sqlite-vector ESM module resolution with platform-specific packages#492
Merged
Conversation
…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
@workglow/cli
@workglow/ai
@workglow/job-queue
@workglow/knowledge-base
@workglow/storage
@workglow/task-graph
@workglow/tasks
@workglow/util
workglow
commit: |
Coverage Report
File CoverageNo changed files found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes module resolution issues with
@sqliteai/sqlite-vectorin ESM contexts by switching from dynamicimport()to CommonJSrequire()viacreateRequire(). This ensures platform-specific sub-packages (darwin-arm64, linux-x86_64, etc.) resolve correctly.Changes
sqlite-vectorvariants (darwin-arm64, darwin-x86_64, linux-arm64, linux-arm64-musl, linux-x86_64, linux-x86_64-musl, win32-x86_64) and added@sqliteai/sqlite-vectorto devDependencies in both root and test packages using catalog referencesimport("@sqliteai/sqlite-vector")withcreateRequire(import.meta.url)to properly resolve platform-specific sub-packages in ESM contextstopKparameter by applying bitwise OR with 0 (topK | 0) to ensure it's treated as a 32-bit integercreateRequire()instead of dynamic import for consistent module resolution and addedawait Sqlite.init()call before database operationsImplementation Details
The core issue was that ESM's dynamic
import()doesn't properly resolve the conditional exports thatsqlite-vectoruses to load platform-specific native bindings. By using CommonJSrequire()viacreateRequire(), 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