fix(ruvector): Node 22 LTS-compatible ONNX WASM loader (#323)#432
Open
fix(ruvector): Node 22 LTS-compatible ONNX WASM loader (#323)#432
Conversation
The bundled `pkg/ruvector_onnx_embeddings_wasm.js` is wasm-bindgen's
`--target bundler` output. Its first line is
import * as wasm from "./ruvector_onnx_embeddings_wasm_bg.wasm";
Node 22 LTS rejects static `.wasm` imports without
`--experimental-wasm-modules`, throwing
`Unknown file extension ".wasm"` and tearing down `initOnnxEmbedder()`
before any user code runs. Node 25+ accepts it natively, which masked
the regression.
Add a Node-friendly sibling entry that uses `fs.readFileSync` +
`WebAssembly.compile/instantiate` and routes the host imports through
the existing `_bg.js` (the import module name `./*_bg.js` was
verified by inspecting the .wasm import section). The bundler-target
file is left untouched so webpack/vite/rollup consumers and `--target
bundler`-style toolchains keep working.
`onnx-embedder.ts` now prefers the new `_node.mjs` entry when present
and falls back to the bundler entry, so older bundles stay loadable.
Verified on Node v22.22.2:
$ node test/onnx-node22-loader.test.mjs
ok: Node-friendly loader exists in src/core/onnx/pkg/
ok: loader produced a module namespace
ok: re-exports __wbg_set_wasm
ok: re-exports WasmEmbedder
ok: re-exports WasmEmbedderConfig
Node v22.22.2 ONNX loader smoke OK
Note: end-to-end `initOnnxEmbedder()` from a clean install also
requires the build script to copy `src/core/onnx/pkg/` into `dist/`
(tracked separately as #354 / #417). This PR is the loader fix only.
Closes #323
Co-Authored-By: claude-flow <ruv@ruv.net>
6 tasks
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
initOnnxEmbedder()failed on Node 22 LTS withError: Unknown file extension ".wasm"because the bundledpkg/ruvector_onnx_embeddings_wasm.jsis wasm-bindgen's--target bundleroutput and starts withimport * as wasm from "./ruvector_onnx_embeddings_wasm_bg.wasm";. Node 22 rejects static.wasmimports without--experimental-wasm-modules; Node 25+ accepts them natively, which masked the regression.Fix
src/core/onnx/pkg/ruvector_onnx_embeddings_wasm_node.mjs: Node-friendly sibling entry that usesfs.readFileSync+WebAssembly.compile/instantiate, with the host imports routed through the existing_bg.js../ruvector_onnx_embeddings_wasm_bg.js) verified by inspecting the WASM binary's import section.instance.exports.__wbindgen_start()if present (mirrors the bundler-target glue).onnx-embedder.tsnow prefers the new_node.mjsentry when present and falls back to the bundler entry — so existing installs without the new file aren't broken by this change.test/onnx-node22-loader.test.mjsregression guard.Proof
On Node v22.22.2 (without
--experimental-wasm-modules):Test plan
Unknown file extension ".wasm").__wbg_set_wasm,WasmEmbedder,WasmEmbedderConfig).tsc --noEmit).onnx-embedder.tsfalls back gracefully when_node.mjsis absent (older bundles still load).initOnnxEmbedder()→ embed text on Node 22 LTS. Requires ONNX WASM files not bundled on clean insteall #354/CLI commands that take a<database>path are broken on freshly-created DBs (andembed textfails on missing ONNX bundle) #417 bundling fix to land for the dist/ path to be populated.Scope notes
initOnnxEmbedder()also requires the build script to copysrc/core/onnx/pkg/→dist/core/onnx/pkg/— tracked separately as ONNX WASM files not bundled on clean insteall #354 and CLI commands that take a<database>path are broken on freshly-created DBs (andembed textfails on missing ONNX bundle) #417. This PR is the loader fix only; once ONNX WASM files not bundled on clean insteall #354/CLI commands that take a<database>path are broken on freshly-created DBs (andembed textfails on missing ONNX bundle) #417 land, the loader change here makes the path work on all supported Node versions.🤖 Generated with claude-flow