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

Cannot bind the library with Vite #268

Open
maelp opened this issue Dec 15, 2023 · 3 comments
Open

Cannot bind the library with Vite #268

maelp opened this issue Dec 15, 2023 · 3 comments

Comments

@maelp
Copy link

maelp commented Dec 15, 2023

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?

@mathiasplans
Copy link

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.

@ietwangwei
Copy link

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

@wuzejinCN
Copy link

// import occ with '?url'. Check follow:

import openCascade from 'opencascade.js/dist/opencascade.full.js'
import openCascadeWasm from 'opencascade.js/dist/opencascade.full.wasm?url'

export async function initOcc() {
return await openCascade({
locateFile: () => openCascadeWasm,
})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants