17
17
*/
18
18
19
19
// 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.
20
21
import * as ONNX_NODE from 'onnxruntime-node' ;
21
22
import * as ONNX_WEB from 'onnxruntime-web' ;
22
23
24
+ /** @type {module } The ONNX runtime module. */
23
25
export let ONNX ;
24
26
25
27
export const executionProviders = [
@@ -29,14 +31,14 @@ export const executionProviders = [
29
31
30
32
if ( typeof process !== 'undefined' && process ?. release ?. name === 'node' ) {
31
33
// Running in a node-like environment.
32
- ONNX = ONNX_NODE ;
34
+ ONNX = ONNX_NODE . default ?? ONNX_NODE ;
33
35
34
36
// Add `cpu` execution provider, with higher precedence that `wasm`.
35
37
executionProviders . unshift ( 'cpu' ) ;
36
38
37
39
} else {
38
40
// Running in a browser-environment
39
- ONNX = ONNX_WEB ;
41
+ ONNX = ONNX_WEB . default ?? ONNX_WEB ;
40
42
41
43
// SIMD for WebAssembly does not operate correctly in recent versions of iOS (>= 16.4).
42
44
// As a temporary fix, we disable it for now.
@@ -46,7 +48,3 @@ if (typeof process !== 'undefined' && process?.release?.name === 'node') {
46
48
ONNX . env . wasm . simd = false ;
47
49
}
48
50
}
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