Open fs-eire opened 4 weeks ago
there are workarounds for issue 3 - but they involve patching this package to remove the "node": null
entries so I am not sure if that can be called a workaround:
https://github.com/ollema/g-split/commit/15f616cb8c10b3a32243ca4c872c1bce0ff44f8e
Summary
This issue is created to track the status of onnxruntime-web's workaround for bundlers.
What is workaround for bundlers and why?
workaround for bundlers means extra codes that required to make onnxruntime-web as a library consumable by a web app or other libraries, while those extra codes are supposed to be unnecessary but exists because of various reasons.
What are the known issues:
import.meta.url
as a runtime JavaScript expression, is usually rewritten into a static string starts with "file://" by WebPack as a default behavior. A few other bundlers followed this behvior. This means it is very difficult to use ESM dynamic import in the implementation.Vite development mode does not support "real" ESM. It uses some complicated steps to transcript the ESM sources into IIFE/cjs. https://github.com/microsoft/onnxruntime/pull/22196 tries to fix this but the fix is incompatible with Vite release mode.
Some framework (eg. SvelteKit) always load onnxruntime-web in a Node.js context even if SSR is disabled . https://github.com/microsoft/onnxruntime/issues/22361#issuecomment-2439411518
Emscripten is not able to generate both ESM/commonJS glue file in a build. (https://github.com/emscripten-core/emscripten/issues/21899)
Why is it difficult to fix:
It's all about dynamic loading with bundler involved.
onnxruntime-web has 4 dynamic loading target:
Considering the following requirements:
It's not hard to conclude that:
For example:
UMD format cannot be supported in CSP. This is because:
proxy worker is not well supported when using with multi-threading. This is because:
new Worker(new URL("ort.min.mjs", import.meta.url), {type: "module"})
, and webpack will use its builtin worker loader to load the worker as a static loaded module.There are more case that makes onnxruntime-web not working out-of-box in different combinations of dev frameworks, bundlers, dev/prod modes and so on, and one fix for a specific usage may even break a specific existing working usage.
It seems that there is no way to make every use scenario work. Need to track issues and find workaround for each.