Skip to content

Conversation

@KingSora
Copy link

@KingSora KingSora commented Oct 23, 2025

Description

Currently the files which are needed for wasm aren't exported from the package at all.
The files in question are:

ort-wasm-simd-threaded.wasm
ort-wasm-simd-threaded.jsep.wasm
ort-wasm-simd-threaded.asyncify.wasm
ort-wasm-simd-threaded.mjs
ort-wasm-simd-threaded.jsep.mjs
ort-wasm-simd-threaded.asyncify.mjs

This PR changes that and adds them to exports field in the package.json.

Motivation and Context

Bundlers like webpack use the copyPlugin to move those files into the public directory, so the files can be accessed by a stable url. However more advanced and "state of the art" bundlers like vite are able to import asset urls directly. Vite takes the asset, moves it to to public assets folder (possibily renames the asset and adds a hash etc.). The imported value then is the bundled assets final url.

Those urls can then be used in the env.wasm.wasmPaths directly. In vites case the full code example is:

import wasmUrl from 'onnxruntime-web/ort-wasm-simd-threaded.wasm?url';
import mjsUrl from 'onnxruntime-web/ort-wasm-simd-threaded.mjs?url';

env.wasm.wasmPaths = {
  wasm: wasmUrl,
  mjs: mjsUrl,
};

With those added exports we can leverage more of the bundlers capabilities and in vites case there isn't any need to add any additional configs. It would just work.

When importing we also get proper suggestions:
imports


I would like additional tests to ensure that the exports are available, but I couldn't make the e2e tests work on my system. I would appreciate some guidance on that topic.

@KingSora
Copy link
Author

@fs-eire when I'm trying to run npm run test:e2e in the js/web directory I'm getting the following error: cannot find exactly single package for onnxruntime-web. This error prevents me to write an meaningful test.

@fs-eire
Copy link
Contributor

fs-eire commented Oct 24, 2025

@fs-eire when I'm trying to run npm run test:e2e in the js/web directory I'm getting the following error: cannot find exactly single package for onnxruntime-web. This error prevents me to write an meaningful test.

Looks like the CI passes, so this may indicate that you are not running npm run test:e2e in the expected order. you need run npm pack in /js/common/ and /js/web/ to create the 2 .tgz files and then run the npm run test:e2e

},
"./ort-wasm-simd-threaded.wasm": "./dist/ort-wasm-simd-threaded.wasm",
"./ort-wasm-simd-threaded.jsep.wasm": "./dist/ort-wasm-simd-threaded.jsep.wasm",
"./ort-wasm-simd-threaded.asyncify.wasm": "./dist/ort-wasm-simd-threaded.asyncify.wasm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also add .jspi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

@KingSora
Copy link
Author

@fs-eire Thanks for the info, npm pack was missing - might be worth adding it to the docs.

I've added some e2e tests which test the said exports with vite and its ?url import feature.

@KingSora
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants