Skip to content
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

Fix error using onnxruntime-web on next.js by with dynamic CDN load #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix error using onnxruntime-web on next.js by dynamically loading fil…
…es from CDN
hiyeonKim committed Dec 12, 2024
commit 4d9e59fb700ac39d4e0745dbe9168c2a743f7363
352 changes: 319 additions & 33 deletions package-lock.json
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@
"deploy-assets": "node -r dotenv/config ./scripts/deploy-assets.mjs",
"tag": "git tag $npm_package_version & git push origin $npm_package_version",
"package:pack": "npm run package:pack --workspaces --if-present",
"prepare": "husky"
"prepare": "husky",
"postinstall": "patch-package"
},
"devDependencies": {
"chalk": "~5.3.0",
@@ -40,5 +41,8 @@
"onchange": "~7.1.0",
"prettier": "^3.2.5",
"yaml": "~2.3.4"
},
"dependencies": {
"patch-package": "^8.0.0"
}
}
12 changes: 2 additions & 10 deletions packages/web/src/onnx.ts
Original file line number Diff line number Diff line change
@@ -28,17 +28,9 @@ async function createOnnxSession(model: any, config: Config) {
ort.env.wasm.numThreads = caps.maxNumThreads();
ort.env.wasm.proxy = proxyToWorker;

// The path inside the resource bundle
const baseFilePath = useWebGPU
? '/onnxruntime-web/ort-wasm-simd-threaded.jsep'
: '/onnxruntime-web/ort-wasm-simd-threaded';

const wasmPath = await loadAsUrl(`${baseFilePath}.wasm`, config);
const mjsPath = await loadAsUrl(`${baseFilePath}.mjs`, config);

ort.env.wasm.wasmPaths = {
mjs: mjsPath,
wasm: wasmPath
mjs: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.mjs',
wasm: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.wasm'
};

if (config.debug) {
13 changes: 13 additions & 0 deletions patches/onnxruntime-web+1.20.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/onnxruntime-web/package.json b/node_modules/onnxruntime-web/package.json
index 3ec7652..8afaaa0 100644
--- a/node_modules/onnxruntime-web/package.json
+++ b/node_modules/onnxruntime-web/package.json
@@ -97,7 +97,7 @@
},
"./webgpu": {
"node": null,
- "import": "./dist/ort.webgpu.bundle.min.mjs",
+ "import": "./dist/ort.webgpu.min.mjs",
"require": "./dist/ort.webgpu.min.js",
"types": "./types.d.ts"
}