opencascade.js icon indicating copy to clipboard operation
opencascade.js copied to clipboard

Cannot bind the library with Vite

Open maelp opened this issue 1 year ago • 6 comments

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?

maelp avatar Dec 15 '23 15:12 maelp

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.

mathiasplans avatar Dec 22 '23 11:12 mathiasplans

I found a solution with three steps:

  1. Use the vite-plugin-wasm plugin, add it into your vit.config

  2. Add the wasm file to optimizeDeps.exinclude into vite.config.js

    exclude: ["opencascade.js/dist/opencascade.full.wasm"]
    
  3. Add the suffix ?url to the wasm import path like opencascade.js/dist/opencascade.full.wasm?url

ietwangwei avatar Jul 02 '24 03:07 ietwangwei