-
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] Error when using Web Workers on Next.js #22113
Comments
@illbexyz Can you try using onnxruntime 1.19 in a clean environment? |
@satyajandhyala This is already the most minimal reproduction I could give. It's just |
This is a known issue. If you use webpack loading onnxruntime-web as ESM, you need this line in your webpack config:
Explaination: onnxruntime-web use May be a good idea to update our document/examples. |
Hey @fs-eire, thanks for your time! I tried adding the following to webpack: (config) => {
config.module.parser.javascript.importMeta = false;
return config;
}, But now I get a different error:
I updated the reproductions if you wanna have a look. |
I made a PR #22196. Hope to workaround this issue without having to modify webpack config from user side. |
This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details. |
The issue is not resolved. I am still working on it. |
@fs-eire I'm also facing similar issue. Were you able to create a fix for it? |
It is still on my list. However I have multiple tasks to do so it may take a while. #22196 is an attempt but testing result shows that it does not fix everything. #22615 is the issue that tracks and explains why it is hard to fix. I would be appreciated if anyone can help contribute or provider detailed information/clues to the issue. |
@fs-eire until the issue is fixed for good, it would great to have a way to patch |
@illbexyz if you are OK with loading the .mjs file and .wasm file dynamically from CDN, here is the steps:
|
Describe the issue
I get the following error when using
onnxruntime-web
on Next.js with web workers:Error: no available backend found. ERR: [wasm] TypeError: Failed to fetch, [cpu] Error: multiple calls to 'initWasm()' detected.
I had no issues with
[email protected]
.I believe the issue is that Next.js is trying to load the file from the filesystem:
file:///Users/alberto.nicoletti/node_modules/onnxruntime-web/dist/ort.bundle.min.mjs
Additional notes:
onnx.env.wasm.numThreads = 2
Error: no available backend found. ERR: [wasm] SecurityError: Failed to construct 'Worker': Script at 'file:///Users/alberto.nicoletti/node_modules/onnxruntime-web/dist/ort.bundle.min.mjs' cannot be accessed from origin 'http://localhost:3000'., [cpu] Error: previous call to 'initWasm()' failed.
.Network requests screenshot:
To reproduce
The following reproductions are a bare Next.js 14 starter repository with
[email protected]
.onnx.env.wasm.proxy = true
.onnx.env.wasm.numThreads = 2
.crossOriginIsolation
headers here: https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-threads/next.config.mjsUrgency
Kinda urgent: every Next.js project is impacted.
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.19.2
Execution Provider
'wasm'/'cpu' (WebAssembly CPU)
The text was updated successfully, but these errors were encountered: