I am trying to build the sample app from the yew documentation (here) and I am getting the error below. If feels that it's something wrong with my environment since there are only 3 files to change for the app.
Any input is welcome.
osboxes@osboxes:~/src/rust-learning/yewwwww$ trunk serve
2023-03-31T18:14:01.101996Z INFO starting build
2023-03-31T18:14:01.102723Z INFO spawning asset pipelines
2023-03-31T18:14:01.208652Z INFO building yewwwww
Finished dev [unoptimized + debuginfo] target(s) in 0.23s
2023-03-31T18:14:01.485763Z INFO fetching cargo artifacts
2023-03-31T18:14:01.743985Z INFO processing WASM for yewwwww
2023-03-31T18:14:01.780445Z INFO using system installed binary app=wasm-bindgen version=0.2.84
2023-03-31T18:14:01.780708Z INFO calling wasm-bindgen for yewwwww
error: failed getting Wasm module for '/home/osboxes/src/rust-learning/yewwwww/target/wasm32-unknown-unknown/debug/yewwwww.wasm'
Caused by:
0: failed to parse bytes
1: unexpected character '\0'
--> <anon>:1:1
|
1 |
| ^
2023-03-31T18:14:02.182340Z ERROR ❌ error
error from HTML pipeline
Caused by:
0: error from asset pipeline
1: wasm-bindgen call returned a bad status
2023-03-31T18:14:02.182519Z INFO serving static assets at -> /
2023-03-31T18:14:02.182563Z INFO server listening at http://127.0.0.1:8080
cargo install --locked wasm-bindgen-cli^Cosboxes@osboxes:~/src/rust-learning/yewwwww$
Not sure what's wrong with my environment. Here's my code
Cargo.toml
[package]
name = "yewwwww"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
src/main.rs
use yew::prelude::*;
#[function_component]
fn App() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
move |_| {
let value = *counter + 1;
counter.set(value);
}
};
html! {
<div>
<button {onclick}>{ "+1" }</button>
<p>{ *counter }</p>
</div>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Yew App</title>
</head>
</html>
rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/osboxes/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
beta-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.61.0-x86_64-unknown-linux-gnu
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-unknown-linux-gnu
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.68.2 (9eb3afe9e 2023-03-27)