Skip to content
Latchkey

rustc "error[E0463]: can't find crate for X" in CI

rustc was told to use a crate but could not find its compiled .rlib/.rmeta on the search path. The dependency was not built, the target's standard library is not installed, or a stale target directory is confusing the compiler.

What this error means

Compilation fails with "error[E0463]: can't find crate for X" naming a dependency or, for cross builds, std or core.

rustc
error[E0463]: can't find crate for `serde`
 --> src/main.rs:1:1
  |
1 | use serde::Serialize;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

Common causes

The dependency is not declared or not built

The crate is referenced in code but missing from [dependencies], or its build failed earlier so no artifact exists for rustc to link.

The target std is not installed (cross builds)

When the crate is std or core, the precompiled standard library for the requested --target is not installed via rustup.

How to fix it

Declare the dependency or build it first

  1. Add the crate to [dependencies] in Cargo.toml if it is missing.
  2. Run a clean build so the dependency artifact is produced.
  3. Confirm an earlier compile error did not leave the dependency unbuilt.
Terminal
cargo add serde
cargo clean && cargo build

Install the target std for cross compilation

If E0463 names std/core, add the rustup target so its precompiled standard library exists.

Terminal
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl

How to prevent it

  • Declare every crate you use in Cargo.toml.
  • Add required rustup targets before cross builds.
  • Run cargo clean when a stale target directory misbehaves.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →