Menci / vite-plugin-wasm

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

Top level await support #52

Open ESchouten opened 7 months ago

ESchouten commented 7 months ago

I get the following error: This require call is not allowed because the imported file "vite-plugin-wasm-namespace:/node_modules/.pnpm/@foxglove+wasm-bz2@0.1.1/node_modules/@foxglove/wasm-bz2/wasm/module.wasm" contains a top-level await

Is there any way to enable top-level await support for wasm dependencies?

Menci commented 7 months ago

Seems the error is thrown by esbuild?

nick-benyo commented 7 months ago

Second this, having the exact same problem:

The file "node_modules/wasm-brotli/wasm_brotli_browser.js" imports the file
  "vite-plugin-wasm-namespace:/<removed>/node_modules/wasm-brotli/wasm_brotli_browser_bg.wasm"
  here:

    node_modules/wasm-brotli/wasm_brotli_browser.js:1:22:
      1 │ import * as wasm from './wasm_brotli_browser_bg.wasm';
        ╵                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The top-level await in
  "vite-plugin-wasm-namespace:/<removed>/node_modules/wasm-brotli/wasm_brotli_browser_bg.wasm"
  is here:

    vite-plugin-wasm-namespace:/<removed>/node_modules/wasm-brotli/wasm_brotli_browser_bg.wasm:44:27:
      44 │ const __vite__wasmModule = await initWasm({ "./wasm_brotli_browser.js": { __wbindgen_string_new: __vite__wasmImport_0_0, __wbindgen_rethrow: __vite__wasmImport_...
         ╵                            ~~~~~

This error is encountered after running vite server, no fail on build

inyellowbus commented 6 months ago

Same. Error when dev, but no error when build. Also using vite-plugin-top-level-await