-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web] ES6 modules #10913
Comments
I've just realised that you can simply write this: (Edit: wrong - read next comment) import "https://cdn.jsdelivr.net/npm/[email protected]/dist/ort.js" And it will create the I'll leave this issue open since it still would be nice to have proper ES6 module support. |
Oh, but now I see that a new problem arises. If we do a bare module import like this: import "https://cdn.jsdelivr.net/npm/[email protected]/dist/ort.js"; then Here's an example of some code in var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; You can see other examples by searching [email protected]/dist/ort.js for "currentScript" using I was only able to find one reference to @hanbitmyths, @fs-eire Wondering if you could provide guidance on if/how I can submit a pull request to fall back to Note that currently it falls back to |
I will take a look at this issue. |
Any workarounds to make onnx runtime works on Deno ? |
@fs-eire Wondering if you could just add this to the top of the published if(typeof document === "undefined") {
var document = {currentScript:{src:import.meta.url}};
} I.e. just add a "dummy" |
I found that Emscripten actually supports this feature. I am trying to make a change to support it for ORTWEB. |
I published a repo with a working version of onnx-runtime-web on Deno (note: it discard multithreading !). https://github.com/nestarz/onnx_runtime I built the wasm files with:
|
@nestarz thank you so much for this example! it's a good learning for me. Currently, we have 3 different scenarios for consuming the onnxruntime-web library:
There are a few hacks we currently doing in our build process :
combining of the hacks, it makes ORT web very difficult to support ES6 module for now. We need to re-think the balance between the benefit of (single-file distribution and file size) VS. (easy-to-maintain code and webpack friendly) |
#15772: This change turns onnxruntime-common into a ESModule/commonJS "dual" package, which means it is able to comsumed as either a ESM or CJS module. When this is merged, following-up work will start for onnxruntime-web. |
Just realised that OR Web currently works with Deno by simply setting import "https://cdn.jsdelivr.net/npm/[email protected]/dist/ort.js";
ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/[email protected]/dist/";
let onnxImageSession = await ort.InferenceSession.create("https://huggingface.co/rocca/openai-clip-js/resolve/main/clip-image-vit-32-float32.onnx", { executionProviders: ["wasm"] }); |
added ESM exports for onnxruntime-web in latest main branch. ( will later paste nightly build version ) However Please try it out. If it's still not working, let me know the repro steps and I will fix |
Awesome! Awaiting nightly script CDN URL 🫡 |
Please try 1.17.0-dev.20231014-ae211999dd |
Hmm, for some reason on JSDelivr I get a 403 HTTP error with this message: "Package size exceeded the configured limit of 150 MB.": let ort = await import("https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/ort.js"); I tried
Then it loads but then throws:
And if I try: import ort from "./node_modules/onnxruntime-web/dist/esm/ort.js"; Then it throws:
And using import ort from "https://esm.sh/[email protected]/dist/esm/ort.js"; also throws:
|
### Description This PR tries to fix a part of the NPM package consuming problems for onnxruntime-web (ES module) as described in #10913: - reduce the package size to fit the 150MB restriction in jsdelivr, by removing dev build targets for uncommon exports - add default export to support `import ort from 'onnxruntime-web';` (currently only support `import * as ort from 'onnxruntime-web';`
### Description This PR tries to fix a part of the NPM package consuming problems for onnxruntime-web (ES module) as described in microsoft#10913: - reduce the package size to fit the 150MB restriction in jsdelivr, by removing dev build targets for uncommon exports - add default export to support `import ort from 'onnxruntime-web';` (currently only support `import * as ort from 'onnxruntime-web';`
### Description This PR tries to fix a part of the NPM package consuming problems for onnxruntime-web (ES module) as described in microsoft#10913: - reduce the package size to fit the 150MB restriction in jsdelivr, by removing dev build targets for uncommon exports - add default export to support `import ort from 'onnxruntime-web';` (currently only support `import * as ort from 'onnxruntime-web';`
Is your feature request related to a problem? Please describe.
I'm trying to get ONNX Runtime Web working in Deno. Deno maintains very close compatibility with the browser, but there's no concept of HTML/DOM since it's a server-side language, so the usual script tag import method is not possible.
System information
Describe the solution you'd like
It would be great if the package had an ES6 modules build available so that it could be imported like this:
The text was updated successfully, but these errors were encountered: