Skip to content

Commit 4feb8b4

Browse files
committed
Correctly use default module if present
1 parent 14c02f8 commit 4feb8b4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/backends/onnx.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818

1919
// NOTE: Import order matters here. We need to import `onnxruntime-node` before `onnxruntime-web`.
20+
// In either case, we select the default export if it exists, otherwise we use the named export.
2021
import * as ONNX_NODE from 'onnxruntime-node';
2122
import * as ONNX_WEB from 'onnxruntime-web';
2223

24+
/** @type {module} The ONNX runtime module. */
2325
export let ONNX;
2426

2527
export const executionProviders = [
@@ -29,14 +31,14 @@ export const executionProviders = [
2931

3032
if (typeof process !== 'undefined' && process?.release?.name === 'node') {
3133
// Running in a node-like environment.
32-
ONNX = ONNX_NODE;
34+
ONNX = ONNX_NODE.default ?? ONNX_NODE;
3335

3436
// Add `cpu` execution provider, with higher precedence that `wasm`.
3537
executionProviders.unshift('cpu');
3638

3739
} else {
3840
// Running in a browser-environment
39-
ONNX = ONNX_WEB;
41+
ONNX = ONNX_WEB.default ?? ONNX_WEB;
4042

4143
// SIMD for WebAssembly does not operate correctly in recent versions of iOS (>= 16.4).
4244
// As a temporary fix, we disable it for now.
@@ -46,7 +48,3 @@ if (typeof process !== 'undefined' && process?.release?.name === 'node') {
4648
ONNX.env.wasm.simd = false;
4749
}
4850
}
49-
50-
// We select the default export if it exists, otherwise we use the named export.
51-
// This allows us to run in both node and browser environments.
52-
ONNX = ONNX.default ?? ONNX;

0 commit comments

Comments
 (0)