Can't compile project for WASM, some weird version-mismatch?

Trying to compile a project in bevy game-engine, everything is fine with regular compiles. But trying to compile to WASM, using wasm-bindgen library, and I get:

cargo run --release --target wasm32-unknown-unknown

Error: it looks like the Rust project used to create this wasm file was linked against
version of wasm-bindgen that uses a different bindgen format than this binary:

  rust wasm file schema version: 0.2.82
     this binary schema version: 0.2.81

Currently the bindgen format is unstable enough that these two schema versions
must exactly match. You can accomplish this by either updating the wasm-bindgen
dependency or this binary.

You should be able to update the wasm-bindgen dependency with:
    cargo update -p wasm-bindgen
or you can update the binary with
    cargo install -f wasm-bindgen-cli

Neither of the suggested fixes worked. Additionally, I tried pinning it in my Cargo.toml:

[dependencies]
wasm-bindgen = { version = "0.2.81" }
bevy = { version = "0.8.0" }

And then nuked every directory that I suspected might contain relevant code:

  • /target
  • ~/.cargo/git
  • ~/.cargo/register

but no joy. I don't even what "this binary" is referring to... So is there any way to control for, and build things, with the correct version?

Update: I didn't remove ~/.cargo/bin, because it has other packages I wanted to keep. But looking at the cargo-help, it says:
install - Install a Rust binary. Default location is $HOME/.cargo/bin
Am I going to have to change the Rust binary, or something globally?

1 Like
[dependencies]
wasm-bindgen = { version = "0.2.81" }

Means "versions 0.2.81 and greater as long as it's less than 0.3.0"

Try

[dependencies]
wasm-bindgen = { version = "= 0.2.81" }
1 Like

That definitely makes sense. :slight_smile: However, I have found out that my assumptions were wrong - wasm-bindgen isn't a project package, but installed at the Cargo "system-level". So the "suggested-fix" was on the right track, I just had to do this.

cargo install -f wasm-bindgen-cli --version 0.2.82

Which gave me this:

jcrawford@jcrawford-NUC:~/.cargo$ cargo install --list
wasm-bindgen-cli v0.2.82:
    wasm-bindgen
    wasm-bindgen-test-runner

Which still didn't work! I have no idea what this binary schema version: 0.2.81 refers to.

Ahh I misunderstood, I thought you had things working and something broke at some point

You may want to run through the wasm-bindgen tutorial quick which walks you through getting an environment set up

https://rustwasm.github.io/docs/book/game-of-life/hello-world.html

I skimmed right past it but "cargo run" isnt typically going to work with wasm unless something has drastically changed since I last played with wasm-bindgen

Well, actually I did have this working (for a similar project using bevy) - but for Bevy 0.7. I am now upgrading to v0.8, and it's spotty... And just ran everything again, nuked everything again, put your version-suggestion in Cargo.toml, and the Cargo.lock has:

[[package]]
name = "wasm-bindgen"
version = "0.2.82"

Which I'd have thought was enough. But again, something is breaking... Some binary somewhere is at 2.81.

Just to confirm - I went to another project, that's using Bevy 0.7 and re-compiled it. It actually showed wasm-bindgen=0.2.81 in the build-process - as well as running find in a Browser.

So I am back to not understanding what wasm-bindgen really is - as the cargo-list showed, it's a package installed under ~/.cargo/bin, and is version 0.2.82. But if so, how did the 0.7 project I rebuilt, work?

So is wasm-bindgen a system-package that gets installed globally? Or a project-package, that gets built per-project?

You can't directly run a wasm binary directly.

cargo run --release --target wasm32-unknown-unknown doesn't really make sense. Are you sure you weren't using the wasm-pack CLI to build and run like the wasm-bingen tutorial recommends? Or the wasm-bindgen cli tool?

At this point I'm sure of very little. :slight_smile: I probably did install cargo-pack earlier. But two comments.

First, for Bevy 0.7, the cargo run --release --target wasm... does work, and I just confirmed it on another project. However, it's possible it doesn't work in Bevy 0.8.

Second comment - I just did

wasm-bindgen --out-dir ./web/ --target web ./target/wasm32-unknown-unknown/release/bevy-verlet.wasm
python -m http.server --directory web

And it's serving the web-page. It's just a directory-listing, I need to add the HTML, but it's at least doing something. So possibly I just can't use the earlier run-release, and have to actually do a webserver.

And dang, it's actually working. I have stuff happening in the Browser.

So I guess whatever I was doing, for v0.7, was possibly "unsupported", or maybe a bug, I don't know enough to say at this point.

Anyway, thanks for help, it pointed me away from what I was doing, to the right direction.

Update: minor point - I didn't just make up the cargo-run stuff. :slight_smile: After looking around, got it from Bevy Cheatbook. However, that does require installing another "system-level" package, wasm-server-runner.

Ahh I didn't know about the runner setting, that's good to know! That component is probably what's out of date then

This question is googling nicely for this problem so I'll add my comments here - I have the same symptoms compiling a yew client. It is hard to debug, but you can see the version of the dependencies in the Cargo.lock file. I then deleted the Cargo.lock file, and cargo clean and rebuild, then the mismatch finally went away.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.