-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[js/web] ESM: use the bundled target as default export #20991
Conversation
🔥 |
This is somehow broken again in the latest dev releases. For example in 1.21.0-dev.20250117-db8e10b0b9 |
Could you please create a new issue and describe the reproduce steps? I will take a look if I can reproduce it. |
Thank you @fs-eire! I'm using transformer.js which depends on onnxruntime-web. Trying to initialize the model in a Chrome extension's background js, but got this error:
Project is is a little messy to extract out, but if you clone the https://github.com/huggingface/transformers.js/tree/main/examples/extension project and upgrade it to 3.3.0+, you'll see this issue. Anything below 3.2.4 works totally fine. @xenova in case this is something you have noticed too. |
Ah, I see. so this is a service worker use case. There are some limitation in service worker, for example, it cannot use dynamic loading. I am tracking the status of supporting service worker for transformer.js in #23257 |
Thanks! Just wondering, is dynamic loading only used in the newer dev releases like 1.21.0-dev.20250117-db8e10b0b9? Since the older one works totally fine, like 1.21.0-dev.20241205-d27fecd3d3 |
Yes, it is because of this change. But simply reverting it will not fix. Since it is a use case of transformersjs, a workaround for current version is to set I am working on figuring out the best solution for problems of exports for transformerjs. Some details are here: huggingface/transformers.js#1161 |
Somehow still got the error. Is this the right way to set the
|
This should work in my understanding. Could you share a full example for me to debug? |
Sure, prepared one here: https://github.com/qdrk/vite-web-extension To reproduce
Thanks in advance for looking into it! |
I can reproduce the issue locally. The solution is:
|
I can confirm the workaround works for the repro repo! Even though the issue still exists for my other project, but it's probably because it's setup slightly differently. Thank you so much @fs-eire for the prompt resolution! |
Multi-threading seems to have some issue too, got "Worker is not defined" when creating the inferenceSession. |
(Please correct me if I’m wrong) in my understanding, creating a Worker in MV3 is not allowed, so you just have to use single thread. |
Description
ESM: use the bundled target as default export
In this change, the default import of the following entries:
will use the "bundled" version, which has no dynamic import.
This change should only apply to ESM on web.