Skip to content

Commit 9c18671

Browse files
authored
Fix inference unable to run due to JS WASM runtime not being bundled into onnxruntime-web/wasm build (#24836)
### Description Fixes inference error from `ort-wasm-simd-threaded.mjs` not being bundled into `ort.wasm.bundle.min.mjs` as it is for other `bundle.min.mjs` builds. ### Motivation and Context To decrease my app's bundle size, I followed the [conditional importing guide](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js/importing_onnxruntime-web#conditional-importing) and imported the WASM-only build: ```diff - import * as ort from 'onnxruntime-web'; + import * as ort from 'onnxruntime-web/wasm'; ``` After this change, creating an inference session would result in: `TypeError: Failed to resolve module specifier './ort-wasm-simd-threaded.mjs'`. This was because `ort-wasm-simd-threaded.mjs` was not bundled into the build at `onnxruntime-web/wasm`, which points to `ort.wasm.bundle.min.mjs`, despite how its name suggests. In other builds with `bundle` in their name, the module is bundled, yet it was not done so in the WASM one. This PR bundles the Javascript WASM runtime in to match the other builds, fixing the error.
1 parent d520798 commit 9c18671

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

js/web/script/build.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,12 @@ async function main() {
644644
isProduction: true,
645645
outputName: 'ort.wasm.bundle',
646646
format: 'esm',
647-
define: { ...DEFAULT_DEFINE, 'BUILD_DEFS.DISABLE_JSEP': 'true', 'BUILD_DEFS.DISABLE_WEBGL': 'true' },
647+
define: {
648+
...DEFAULT_DEFINE,
649+
'BUILD_DEFS.DISABLE_JSEP': 'true',
650+
'BUILD_DEFS.DISABLE_WEBGL': 'true',
651+
'BUILD_DEFS.ENABLE_BUNDLE_WASM_JS': 'true',
652+
},
648653
});
649654
// ort.webgl[.min].[m]js
650655
await addAllWebBuildTasks({

js/web/test/e2e/src/cjs-js/main.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
const ort = require('onnxruntime-web/wasm');
77
const { setupMultipleThreads, testInferenceAndValidate } = require('./shared');
88

9-
if (typeof SharedArrayBuffer === 'undefined') {
10-
it('Browser package consuming test - single-thread - [js][commonjs]', async function () {
11-
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
12-
});
13-
} else {
14-
it('Browser package consuming test - multi-thread - [js][commonjs]', async function () {
15-
setupMultipleThreads(ort);
16-
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
17-
});
9+
if (typeof it !== 'undefined') {
10+
if (typeof SharedArrayBuffer === 'undefined') {
11+
it('Browser package consuming test - single-thread - [js][commonjs]', async function () {
12+
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
13+
});
14+
} else {
15+
it('Browser package consuming test - multi-thread - [js][commonjs]', async function () {
16+
setupMultipleThreads(ort);
17+
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
18+
});
19+
}
1820
}

js/web/test/e2e/src/esm-js/main.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import * as ort from 'onnxruntime-web/wasm';
77
import { setupMultipleThreads, default as testInferenceAndValidate } from './shared.js';
88

9-
if (typeof SharedArrayBuffer === 'undefined') {
10-
it('Browser package consuming test - single-thread - [js][esm]', async function () {
11-
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
12-
});
13-
} else {
14-
it('Browser package consuming test - multi-thread - [js][esm]', async function () {
15-
setupMultipleThreads(ort);
16-
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
17-
});
9+
if (typeof it !== 'undefined') {
10+
if (typeof SharedArrayBuffer === 'undefined') {
11+
it('Browser package consuming test - single-thread - [js][esm]', async function () {
12+
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
13+
});
14+
} else {
15+
it('Browser package consuming test - multi-thread - [js][esm]', async function () {
16+
setupMultipleThreads(ort);
17+
await testInferenceAndValidate(ort, { executionProviders: ['wasm'] });
18+
});
19+
}
1820
}

0 commit comments

Comments
 (0)