Skip to content

[Web] Error when using Web Workers on Next.js #22113

@illbexyz

Description

@illbexyz

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:

image

To reproduce

The following reproductions are a bare Next.js 14 starter repository with [email protected].

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:webissues related to ONNX Runtime web; typically submitted using templatestaleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions