rustup "the wasm32-unknown-unknown target may not be installed" in CI
cargo tried to compile for wasm32-unknown-unknown but the runner's toolchain has no std for that target. rustup only ships the host target by default, so you must add the wasm target explicitly.
What this error means
A wasm build fails with "error[E0463]: can't find crate for std" and the note "the wasm32-unknown-unknown target may not be installed". Host builds compile fine.
error[E0463]: can't find crate for `std`
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`Common causes
The wasm target was never added to the toolchain
rustup installs only the host target by default. Without rustup target add wasm32-unknown-unknown, there is no precompiled std for wasm, so the crate graph cannot link.
A pinned toolchain that lacks the target
A rust-toolchain.toml selects a channel, but CI added the target to a different toolchain than the one the build actually uses.
How to fix it
Add the wasm target before building
- Run
rustup target add wasm32-unknown-unknownin a step before the build. - Build with
--target wasm32-unknown-unknownso the added target is used. - If a toolchain is pinned, add the target to that same toolchain.
rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknownDeclare the target in the toolchain action
The setup action can install the target so it always matches the active toolchain.
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknownHow to prevent it
- Add the wasm target in the same step or action that selects the toolchain.
- List required targets in your toolchain setup action so they cannot drift.
- Build with an explicit
--targetso the intended target is unambiguous.