-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
platform:webissues related to ONNX Runtime web; typically submitted using templateissues related to ONNX Runtime web; typically submitted using templatestaleissues that have not been addressed in a while; categorized by a botissues that have not been addressed in a while; categorized by a bot
Description
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:
- See Request URL in the following screenshot
file:///Users/alberto.nicoletti/node_modules/onnxruntime-web/dist/ort.bundle.min.mjs
Additional notes:
- I have no issues when not using web workers
- I obtain a slightly different error when disabling the proxy but setting
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.
.- In this case there are no network requests being made but I believe these issues are likely related.
Network requests screenshot:

To reproduce
The following reproductions are a bare Next.js 14 starter repository with [email protected]
.
- Proxy error reproduction here: https://github.com/illbexyz/nextjs-onnxruntime/tree/wasm-proxy
- See https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-proxy/src/pages/components/OnnxButton.tsx where I use a web worker by enabling
onnx.env.wasm.proxy = true
.
- See https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-proxy/src/pages/components/OnnxButton.tsx where I use a web worker by enabling
- Multi-thread reproduction here: https://github.com/illbexyz/nextjs-onnxruntime/tree/wasm-threads
- See https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-threads/src/pages/components/OnnxButton.tsx where I use
onnx.env.wasm.numThreads = 2
. - In this reproduction I also added
crossOriginIsolation
headers here: https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-threads/next.config.mjs
- See https://github.com/illbexyz/nextjs-onnxruntime/blob/wasm-threads/src/pages/components/OnnxButton.tsx where I use
Urgency
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)
loretoparisi, gianlourbano, simonedeldeo-mxm and dulayjm
Metadata
Metadata
Assignees
Labels
platform:webissues related to ONNX Runtime web; typically submitted using templateissues related to ONNX Runtime web; typically submitted using templatestaleissues that have not been addressed in a while; categorized by a botissues that have not been addressed in a while; categorized by a bot