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

Deps optimization in development mode breaks webassembly from the local filesystem packaged with pnpm #15929

Closed
7 tasks done
jthemphill opened this issue Feb 16, 2024 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@jthemphill
Copy link

jthemphill commented Feb 16, 2024

Describe the bug

Deps optimization with vite dev seems to break anything that relies on .wasm files produced locally and bundled via pnpm.

Building and running my project with vite dev will give you a relatively blank page, with this error in the JS console:

Uncaught CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 64 6f @+0

This is because the request for the .wasm file didn't go through. Vite served us index.html instead. The byte sequence 3c 21 64 6f is <!do, the first four bytes of my index.html file.

Navigating to the network tab, you can see that we're requesting the .wasm file from http://localhost:5173/node_modules/.vite/deps/htmf_wasm_bg.wasm, but the dependency optimizer didn't actually move the .wasm file there.

To see what this project is like when it works:

  1. https://jthemphill.github.io/htmf/ contains a working production version
  2. pnpm run preview builds the project correctly, without dependency optimization
  3. The main branch, which still uses npm, will work if you run npm run dev.

Reproduction

https://github.com/jthemphill/htmf/tree/pnpm

Steps to reproduce

To build the pnpm branch of my repo:

jhemphill@macbook-pro htmf/wasm/www % rustup install nightly
jhemphill@macbook-pro htmf/wasm/www % pnpm install
jhemphill@macbook-pro htmf/wasm/www % pnpm run build:wasm-st && pnpm run dev

> htmf@0.5.0 build:wasm-st /Users/jhemphill/oss/htmf/wasm/www
> wasm-pack build --target web --profiling

[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
warning: unstable feature specified for `-Ctarget-feature`: `atomics`
  |
  = note: this feature is not stably supported; its behavior can change in the future

warning: unstable feature specified for `-Ctarget-feature`: `bulk-memory`
  |
  = note: this feature is not stably supported; its behavior can change in the future

warning: unstable feature specified for `-Ctarget-feature`: `mutable-globals`
  |
  = note: this feature is not stably supported; its behavior can change in the future

warning: `htmf` (lib) generated 3 warnings
warning: `htmf-bots` (lib) generated 3 warnings (3 duplicates)
warning: `htmf-wasm` (lib) generated 3 warnings (3 duplicates)
    Finished release [optimized] target(s) in 0.05s
[INFO]: ⬇️  Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: ✨   Done in 0.52s
[INFO]: 📦   Your wasm pkg is ready to publish at /Users/jhemphill/oss/htmf/wasm/pkg.

> htmf@0.5.0 dev /Users/jhemphill/oss/htmf/wasm/www
> vite


  VITE v5.0.12  ready in 123 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

And then navigate to http://localhost:5173/

System Info

System:
    OS: macOS 14.3.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 1.98 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.1 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.15.2 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 121.0.6167.184
    Safari: 17.3.1
  npmPackages:
    @vitejs/plugin-react-swc: ^3 => 3.6.0 
    vite: ^5 => 5.0.12

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Duplicate of #8427

@sapphi-red sapphi-red marked this as a duplicate of #8427 Feb 16, 2024
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Feb 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants