You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Vite + React for a tiny UI. I used WASM with web workers to enable multi-threading. The app is working on the dev server, but in the bundled production build, I am having problems.
I used rustwasm/wasm-bindgen and wasm-pack to generate JavaScript bindings for a Wasm binary, and then I built a TypeScript wrapper around it to achieve worker behavior. I think that since, in the JavaScript artifact generated by Wasm, the .wasm file is not explicitly imported (see), it doesn't get included in the bundle (though I'm not entirely sure). I tried different configurations without getting it to work. :(
I tried following plugins without getting it to work:
Press Greet from worker in both instances, you will see that in dev server the wasm worker is returning the string "Hello from the web worker!" while in prod is not :(.
With problematic codebase GianfrancoBazzani/uni-v4-hook-address-miner
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I am using Vite + React for a tiny UI. I used WASM with web workers to enable multi-threading. The app is working on the dev server, but in the bundled production build, I am having problems.
I used
rustwasm/wasm-bindgen
andwasm-pack
to generate JavaScript bindings for a Wasm binary, and then I built a TypeScript wrapper around it to achieve worker behavior. I think that since, in the JavaScript artifact generated by Wasm, the .wasm file is not explicitly imported (see), it doesn't get included in the bundle (though I'm not entirely sure). I tried different configurations without getting it to work. :(I tried following plugins without getting it to work:
Reproduction
https://github.com/GianfrancoBazzani/uni-v4-hook-address-miner/tree/main/ui
Steps to reproduce
With minimal reproducible example codebase
cd vite-react-wasm-webwokers-example
nvm use
to ensure node v20.18.0yarn
to install depsyarn build-wasm-worker
to build the wasm worker and the js bidingsyarn build
to build the production pageyarn dev
to start the dev server at http://localhost:5173/yarn preview
to start production preview at http://localhost:4173/With problematic codebase
GianfrancoBazzani/uni-v4-hook-address-miner
cd uni-v4-hook-address-miner/ui
yarn
yarn build
yarn preview
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: