Sorry if I'm not very clear, I'm new using rust I create a small project using Yew , everything was working and somehow I made a change (added print!) and now I'm stuck with an error that says "Running target\debug\yew-app.exe
thread 'main' panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets', C:\Users\David Sanchez.cargo\registry\src\index.crates.io-6f17d22bba15001f\js-sys-0.3.64\src\lib.rs:5847:9
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
error: process didn't exit successfully: target\debug\yew-app.exe
(exit code: 101)" , I deleted the change I made and the error is not going away
How are you running your project?
Have you tried anything else besides reverting the change?
Yew is mostly meant for running inside the browser. When doing so you have to compile for the wasm32-unknown-unknown target and use wasm-bindgen for generating the glue javascript code. If you are compiling for a non-wasm target you have to enable the ssr (server side rendering) feature instead.
Oh okay I get it, so if I wanna display an output of a variable through command line I have to enable the wasm-bindgen . Is that correct?
by the way this is code for the main.rs
use yew::prelude::*;
struct Model {
value : i64
}
#[function_component(App)]
fn app() -> Html {
let state = use_state(|| Model {
value: 0
});
let onclick = {
let state = state.clone();
Callback::from(move |_| {
state.set(Model {
value: state.value + 1
})
})
};
let n = "David";
print!("My name is {}",n);
html! {
<div>
<button onclick={onclick}>{"+1"}</button>
<p>{ state.value }</p>
</div>
}
}
fn main() {
yew::Renderer::::new().render();
}
Um, no.
wasm-bindgen
is already used if you are compiling to WASM, because it's pretty much required unless you want to manually (and unsafetly) implement the WASM ABI by hand.
The error message is crystal clear:
cannot call wasm-bindgen imported functions on non-wasm target
I.e., if you are trying to call a function that's wrapped by wasm-bindgen
, then you have to compile for (and run under) WASM. You can't use wasm-bindgen
on a non-WASM target – so you can't run your WASM-targeting code directly on your own computer (likely x64), only in a WASM runtime (likely your browser).