rustwasm / book

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

[4.2] greet keeps saying "Hello, wasm-game-of-life!" #289

Open undavide opened 1 year ago

undavide commented 1 year ago

Describe the bug Following the 4.2 exercise solution at the bottom of the page, the greet() keeps alerting Hello, wasm-game-of-life! instead of Hello, Davide!.

To Reproduce I've followed the tutorial I believe to the letter. To solve the final exercise, I've implemented wasm-game-of-life/src/lib.rs as:

#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}

Also wasm-game-of-life/www/index.js now contains:

wasm.greet("Davide");

I've then run wasm-pack build to rebuild the wasm package, and to be 100% sure, I've closed and re-opened the local server via npm run start.

Expected behavior http://localhost:8080 should pop up an alert saying Hello, Davide!, instead it keeps saying Hello, wasm-game-of-life!

I've made sure that package.json contains the "dependencies": { "wasm-game-of-life": "file:../pkg" }, and npm install has run thereafter.

Additional context rustc 1.66.0, wasm-bindgen 0.2.63.

Thank you!

undavide commented 1 year ago

I've found a crucial bit of information in this page from the wasm-pack docs:

Go into the package.json file, add your package, and remove the hello-wasm-pack dependency from the "dependencies" section.

I've then deleted the entire node_modules folder and run npm install once more. I'd suggest to add it to the documentation. Thanks!