rustwasm / rust-webpack-template

Kickstart your Rust, WebAssembly, and Webpack project!
Apache License 2.0
567 stars 75 forks source link

webpack does not rebuild after rust source files are changed more than twice. #180

Open chmnchiang opened 2 years ago

chmnchiang commented 2 years ago

Describe the Bug

Running yarn start should start a dev-server that will recompile webpack bundle every time the rust source file is changed, but it fails to do so after a few changes.

Steps to Reproduce

  1. In any directory, run npm init rust-webpack my-app to clone the template.
  2. cd my-app and then npm start to start the dev server.
  3. Edit src/lib.rs, for example, duplicate the line console::log_1(...). The browser will reload and we could see Hello world! get print twice in the console.
  4. Edit src/lib.rs, for example, duplicate the line console::log_1(...) again.
  5. See below.

If applicable, add a link to a test case (as a zip file or link to a repository we can clone).

Expected Behavior

The wasm file get recompiled, the bundle is rebuilt and the browser reloads.

Actual Behavior

The wasm file get recompiled, however, the bundle is never rebuild and the browser does not reload. Manually reload the browser does not solve the issue because the bundle isn't rebuilt.

pkelleter commented 2 years ago

@chmnchiang

This seems to be an issue with webpack or webpack-dev-server itself. The wasm file is built with a hash for long-term caching and this hash seems not to update more than once. I had the exact same issue with the game-of-life tutorial and tried to fix it for several hours until i gave up. After seeing that the same issue seems to exist on this repository i got suspicous and changed the versions in webpack from ^ to exact syntax, so instead of ^4.42.0 i went 4.42.0 and so on with all dependencies. That fixes it. So it seems some allegedly "minor" patch broke this in one of the dependencies. And it is still buggy in Webpack 5 even, as it seems, since i tried to fix by migrating to 5 and it didn't work.

If someone has the time to dig deeper and find out what exact dependency causes this and create an issue in the repo of the corresponding library (probably webpack itself) i would be more than glad. Unfortunately I will not find that time in the next weeks myself.

SonyStone commented 2 years ago

If someone has the time to dig deeper and find out what exact dependency causes this and create an issue in the repo of the corresponding library (probably webpack itself) i would be more than glad. Unfortunately I will not find that time in the next weeks myself.

https://github.com/wasm-tool/wasm-pack-plugin/issues/125#issuecomment-1004694898