rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.73k stars 208 forks source link

Changes to code have no effect after first compilation #283

Open erikbrntsn opened 1 year ago

erikbrntsn commented 1 year ago

Changes to code in the exercise of section 4.2 and later have no effect.

Only the result of the first compilation is ever used. Any changes after compiling the first time have no effect. I have tried changing the version in the cargo.toml (as described in #261) + restarted the server + uninstall wasm-game-of-life from www and readded in to the dependencies section + removed the www app and recreated it. None of these steps help :(

The only way I have found to get around the problem is to remove the entire wasm-game-of-life folder and recreating it + applying all the changes to the code before running wasm-pack build.

Note this is the case for the steps in the subsection "Implementing Life" as well and not only in the exercise of section 4.2.

To Reproduce Follow every steps in the tutorial.

Expected behavior All changes to code are reflected in the behavior of the web app.

Additional context I am following the steps in the tutorial and I am pretty sure I have done everything exactly as described. The first changes to the code after first compilation are made in the exercise in 4.2. This I where the problem occurs the first time.

erikbrntsn commented 1 year ago

I have found a simpler workaround.

After you have made your changes to your code and run wasm-pack build do the following:

Steps: remove "wasm-game-of-life": "../pkg" from the dependecies section of package.json run npm install re-add "wasm-game-of-life": "../pkg" to the dependencies run npm install stop the server run npm run start (possibly like this: NODE_OPTIONS=--openssl-legacy-provider npm run start)

I am pretty new to basically all the involved components of this (JS, npm, rust, wasm) so it is very likely there is a better way to accomplish the same in a simpler way. Please let me know

grampajoe commented 1 year ago

I'm having the same issue. It looks like the files in pkg/ are copied into www/npm_modules/wasm-game-of-life/ instead of getting symlinked, and they don't get updated when wasm-pack build or npm install are re-run after editing src/lib.rs.

grampajoe commented 1 year ago

Downgrading to npm@8.19.3 fixes this: npm install -g npm@8.19.3.

It could be a behavior change in 9.1? Possibly related: https://github.com/npm/cli/issues/5868

This is an intentional change in 9.0 (release notes):

install-links config defaults to "true"

The cleanest solution is probably to use npm link ../pkg from www/. The tutorial will need to be updated to reflect the change in npm behavior.

geekynils commented 1 year ago

I have the same problem after following just the very first part (Hello World) and running nom link ../pkg does not seem to have an effect.

CLEckhardt commented 1 year ago

The cleanest solution is probably to use npm link ../pkg from www/. The tutorial will need to be updated to reflect the change in npm behavior.

Thank you!! I kept running into:

WARNING in ./index.js 4:17-25
"export 'Universe' was not found in 'wasm-game-of-life'
 @ ./bootstrap.js

and this fixed it.