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

🐞 Bug report: Ironically, WASM workers do not work in the production build. #19194

Closed
7 tasks done
GianfrancoBazzani opened this issue Jan 13, 2025 · 1 comment
Closed
7 tasks done

Comments

@GianfrancoBazzani
Copy link

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 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:

Reproduction

https://github.com/GianfrancoBazzani/uni-v4-hook-address-miner/tree/main/ui

Steps to reproduce

With minimal reproducible example codebase

  1. clone GianfrancoBazzani/vite-react-wasm-webwokers-example
  2. cd vite-react-wasm-webwokers-example
  3. nvm use to ensure node v20.18.0
  4. yarn to install deps
  5. yarn build-wasm-worker to build the wasm worker and the js bidings
  6. yarn build to build the production page
  7. yarn dev to start the dev server at http://localhost:5173/
  8. yarn preview to start production preview at http://localhost:4173/
  9. 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 :(.

image

With problematic codebase GianfrancoBazzani/uni-v4-hook-address-miner

  1. clone GianfrancoBazzani/uni-v4-hook-address-miner
  2. cd uni-v4-hook-address-miner/ui
  3. yarn
  4. yarn build
  5. yarn preview
  6. If you run the miner the woker never starts.

System Info

System:
    OS: Linux 6.12 Arch Linux
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-1370P
    Memory: 51.78 GB / 62.39 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
    pnpm: 9.15.3 - ~/.nvm/versions/node/v20.18.0/bin/pnpm
  Browsers:
    Brave Browser: 131.1.73.97
  npmPackages:
    @vitejs/plugin-react-swc: ^3.5.0 => 3.7.2 
    vite: ^6.0.1 => 6.0.7

Used Package Manager

yarn

Logs

No response

Validations

@GianfrancoBazzani
Copy link
Author

Proceeding to close since I found the problem:

@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant