Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
292 stars 17 forks source link

Unable to process WASM files from web-tree-sitter #42

Closed devi-prsd closed 11 months ago

devi-prsd commented 11 months ago

I'm trying to use https://swagger.io/docs/open-source-tools/swagger-editor-next/ some of the packages mentioned in there use web-tree-sitter which has its own wasm. I was suggested to use vite-plugin-wasm which then throws these errors

✘ [ERROR] Could not resolve "env"

    vite-plugin-wasm-namespace:/Users/devi.prasad/Documents/depcom-ui/node_modules/@swagger-api/apidom-parser-adapter-yaml-1-2/wasm/tree-sitter-yaml.wasm:43:492:
      43 │ ... as __vite__wasmImport_0_7, __table_base as __vite__wasmImport_0_8, memory as __vite__wasmImport_0_9, __indirect_function_table as __vite__wasmImport_0_10 } from "env";
         ╵                                                                                                                                                          

✘ [ERROR] Could not resolve "GOT.func"

    vite-plugin-wasm-namespace:/Users/devi.prasad/Documents/depcom-ui/node_modules/@swagger-api/apidom-parser-adapter-yaml-1-2/wasm/tree-sitter-yaml.wasm:44:362:
      44 │ ...t_1_2, tree_sitter_yaml_external_scanner_serialize as __vite__wasmImport_1_3, tree_sitter_yaml_external_scanner_deserialize as __vite__wasmImport_1_4 } from "GOT.func";
         ╵                                                                                                                                                                 ~~~~~~~~~~

  You can mark the path "GOT.func" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "GOT.mem"

    vite-plugin-wasm-namespace:/Users/devi.prasad/Documents/depcom-ui/node_modules/web-tree-sitter/tree-sitter.wasm:44:54:
      44 │ import { __heap_base as __vite__wasmImport_1_0 } from "GOT.mem";
         ╵                                                       ~~~~~~~~~

  You can mark the path "GOT.mem" as external to exclude it from the bundle, which will remove this
  error.
deviprsd commented 11 months ago

https://stackblitz.com/edit/vitejs-vite-wqcbgg

Menci commented 11 months ago

web-tree-sitter is NOT WebAssembly esm-integration. Please follow its document to load it.

deviprsd commented 11 months ago

@Menci While I don't disagree it is being treated as such by vite, therefore I had to add this library. I have no control over it because it is a dependency of a dependency for swagger-editor, so If you have any help or idea on how to proceed with vite that would be grateful. I have a discord help post but no one has given me answers yet. Is this even viable with vite in the first place?