web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
8.2k stars 487 forks source link

[Bug]: dev server error when hmr encounters a wasm package change. #6463

Open brochington opened 2 months ago

brochington commented 2 months ago

Version

System:
  OS: macOS 14.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 3.34 GB / 36.00 GB
  Shell: 5.9 - /bin/zsh
Browsers:
  Chrome: 124.0.6367.119
  Safari: 17.4.1

Details

I have a project that contains two packages, one which is a react app, and the other a wasm-pack based wasm library.

Everything works as expected when starting the Rsbuild dev server, but if I rebuild the wasm library, the dev compiler fails with the following console error:

start   Compiling...
ready   Client compiled in 0.14 s
start   Compiling...
ready   Client compiled in 0.01 s
start   Compiling...
error   Compile error: 
Failed to compile, check the errors for troubleshooting.
File: undefined
  × Conflict: Multiple assets emit different content to the same filename index.44be1698c47b3b8a.hot-update.js

start   Compiling...
error   Compile error: 
Failed to compile, check the errors for troubleshooting.
File: undefined
  × Conflict: Multiple assets emit different content to the same filename index.b0c9980bbdb8ffad.hot-update.js

I am unsure why the compiler runs twice as well.

I would like to be able to rebuild the wasm module, and have the hmr pick up the changed package and reload.

Reproduce link

https://github.com/brochington/mult-assets-rsbuild-repro

Reproduce Steps

# At project root

# build wasm bundle
$ npm run build:wasm

# make sure local deps are connected/symlinked
$ npm install 

# run client, start up rsbuild dev
$ npm run client:dev

# In a separate terminal, rebuild wasm

$ npm run build:wasm
9aoy commented 2 months ago

Rebuild multiple times is because wasm build triggers multiple file changes, and rspack's watchOptions.aggregateTimeout time interval is small. Multiple assets emit different content to the same filename This error seems to be a problem with the rspack code. I will transfer this issue to the rspack repo.

9aoy commented 2 months ago

Added a debug log for conflicting assets:

image

original_source:

image

asset_source:

image
stale[bot] commented 2 days ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!