opencascade.js
opencascade.js copied to clipboard
Cannot bind the library with Vite
I'm trying to build the library and import it but I keep having errors such as WebAssembly.instantiate(): Import #0 module="a": module is not an object or function, I'm not sure why
could you perhaps provide a basic project with a vite.config.mts which builds correctly?
Have a similar problem:
vite-plugin-wasm-namespace:/mnt/c/Users/mathi/Documents/solidgram/node_modules/opencascade.js/dist/opencascade.full.wasm:43:35151:
43 │ ..._0_1096, ut as __vite__wasmImport_0_1097, vt as __vite__wasmImport_0_1098, wt as __vite__wasmImport_0_1099 } from "a";
╵ ~~~
You can mark the path "a" as external to exclude it from the bundle, which will remove this error
and leave the unresolved path in the bundle.
I found a solution with three steps:
-
Use the vite-plugin-wasm plugin, add it into your vit.config
-
Add the wasm file to optimizeDeps.exinclude into vite.config.js
exclude: ["opencascade.js/dist/opencascade.full.wasm"] -
Add the suffix
?urlto the wasm import path likeopencascade.js/dist/opencascade.full.wasm?url