From 0d2bff07ce0d07e0cf18b68dded06e45fbe01f81 Mon Sep 17 00:00:00 2001 From: claude_code Date: Mon, 22 Jun 2026 17:40:45 +0300 Subject: [PATCH] fix(dictation): also ship the plain onnxruntime-web wasm variant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The production (rolldown) build resolves onnxruntime-web to the plain wasm backend and fetched /vad/ort-wasm-simd-threaded.mjs, which we did not ship — we only copied the JSEP variant that the Vite dev build uses. That 404'd into the SPA fallback, reproducing "no available backend found / Failed to fetch dynamically imported module" in production. Copy BOTH the JSEP and the plain ort-wasm-simd-threaded.{mjs,wasm} into public/vad/, so the runtime fetch finds a real file regardless of which build the bundler picked. Co-Authored-By: Claude Opus 4.8 --- apps/client/scripts/copy-vad-assets.mjs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/client/scripts/copy-vad-assets.mjs b/apps/client/scripts/copy-vad-assets.mjs index 4e0cccd0..49aaaf1c 100644 --- a/apps/client/scripts/copy-vad-assets.mjs +++ b/apps/client/scripts/copy-vad-assets.mjs @@ -8,7 +8,7 @@ // the current page URL — NOT a CDN. In this SPA that "./" request hits the // client-side catch-all route and gets served index.html (text/html), so the // onnxruntime ESM/wasm backend fails to initialize ("'text/html' is not a valid -// JavaScript MIME type"). We fix that by copying the four needed files into +// JavaScript MIME type"). We fix that by copying the needed runtime files into // public/vad/ and pointing both path constants at the fixed absolute "/vad/". // // These copies are NOT committed (the ORT wasm is ~26 MB); this script runs @@ -33,19 +33,30 @@ const vadDist = path.join( // onnxruntime-web's "exports" map does NOT expose ./package.json, so resolving // it would throw ERR_PACKAGE_PATH_NOT_EXPORTED. It DOES export the exact asset // subpaths we need, so resolve those files directly. -const ortMjs = require.resolve( +// +// ORT ships several wasm backends and which one the app bundle references depends +// on the resolver: Vite dev resolves the JSEP build (ort-wasm-simd-threaded.jsep.*) +// while the production rolldown build resolves the plain build +// (ort-wasm-simd-threaded.*). Ship BOTH variants so the runtime fetch hits a real +// file under /vad/ regardless of which the bundle picked (each .mjs proxy fetches +// its matching .wasm at init). +const ortJsepMjs = require.resolve( "onnxruntime-web/ort-wasm-simd-threaded.jsep.mjs", ); -const ortWasm = require.resolve( +const ortJsepWasm = require.resolve( "onnxruntime-web/ort-wasm-simd-threaded.jsep.wasm", ); +const ortMjs = require.resolve("onnxruntime-web/ort-wasm-simd-threaded.mjs"); +const ortWasm = require.resolve("onnxruntime-web/ort-wasm-simd-threaded.wasm"); // [absolute source path, output filename] const files = [ [path.join(vadDist, "vad.worklet.bundle.min.js"), "vad.worklet.bundle.min.js"], [path.join(vadDist, "silero_vad_v5.onnx"), "silero_vad_v5.onnx"], - [ortMjs, "ort-wasm-simd-threaded.jsep.mjs"], - [ortWasm, "ort-wasm-simd-threaded.jsep.wasm"], + [ortJsepMjs, "ort-wasm-simd-threaded.jsep.mjs"], + [ortJsepWasm, "ort-wasm-simd-threaded.jsep.wasm"], + [ortMjs, "ort-wasm-simd-threaded.mjs"], + [ortWasm, "ort-wasm-simd-threaded.wasm"], ]; fs.mkdirSync(outDir, { recursive: true });