onnxruntime: [Web] ort-wasm-simd.wasm can't be loaded in Electron renderer (using webpack)

Describe the issue

I‘m building a electron app, the ort.js is loaded using script tag, but the wasm file is not loaded in webpack-dev-server
electron packed into an App won’t load either.

<head>
    <base href="../../"> <!-- without this line, the issue still remains -->
    <title>my app</title>
    <script type="text/javascript" src="apps/videoAnalyzer/js/ort.js"></script>
  </head>

i’m sure i have copyed .wasm file near the ort.js file filestruc

the path is incorrect http://ort-wasm-simd.wasm ort-web.min.js?e269:6 GET http://ort-wasm-simd.wasm/ net::ERR_ABORTED 502 (Bad Gateway) err0r1

after some testing i guess the problem is in the “ort-wasm.js” file, but it’s been minified so i can’t do further test; or maybe it is because Electron’s issue

any help would be appreciated

To reproduce

electron app, using webpack boundle and set target to “electron-renderer” test electron version: 22.0.0 and 16.0.6 both version won’t work properly

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.12.0

Execution Provider

WASM

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Most upvoted comments

if you’re already using onnxruntime-web, a tricky workaround would be:

import { env } from "onnxruntime-web";
  env.wasm.wasmPaths = window.location.protocol === 'file:' ? window.location.href.substring(0, window.location.href.indexOf('app.asar')) : ''

copy wasm like this (electron builder):

"extraResources": [
    {
      "from": "node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm",
      "to": ".",
    }
  ],

will be placed to and load from: release/linux-unpacked/resources/ort-wasm-simd-threaded.wasm

@fs-eire thanks for your reply that solve the problem of loading wasm file! but the file finding related function is still not working, now i’m stuck at TypeError: Worker is not a constructor which means when importing the working.js file, it can’t find the js file ee2

caused by this function in ort-wasm-threaded.js function ma(a){return w.locateFile?w.locateFile(a,E):E+a}var na,F,G,fs,H,J; ee3

i guess the locateFile() function is implemented without testing in Electron environment

const ort = require('onnxruntime-web')
async initializeWorkers() {
    ort.env.wasm.wasmPaths = this.wasmPath
   let session = await ort.InferenceSession.create("path to my xx.onnx", { executionProviders: ["wasm"] }); 
   // it stoped here
}

@eisneim do you have it working with electron in production? just curious what packager you use? there are issues with electronforge+webpack and maybe you can spare me from going too far down that rabbit hole 😄

i’m using electron-builder, with no hack! here are the versions i use:

"electron": "^16.0.6",
"electron-builder": "^22.14.10",
"onnxruntime-node": "^1.13.1",

in production, you have to build onnx-runtime binding for differient platforms, darwin, win64, win32 etc.

@FangliangBai 这也回答了你的问题