Fix error[E0463]: can't find crate in Rust / Cargo

beginner๐Ÿฆ€ Rust2026-03-21| Rust (any version), Cargo, Linux / macOS / Windows

Error Message

error[E0463]: can't find crate
#rust#cargo#crate#dependency

The error you're seeing

You added a use statement or an extern crate line, ran cargo build, and got slapped with something like this:

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

Or, if you're writing embedded or no_std code:

error[E0463]: can't find crate for `std`

Three things usually cause this. The crate isn't listed in Cargo.toml. The name is misspelled. Or your build environment is broken or missing a target. Work through the steps below in order โ€” most cases are solved by Step 1 or 2.

Step 1 โ€” Check your Cargo.toml first

Open Cargo.toml and look at the [dependencies] section. If the crate isn't there, Cargo has no way to download or link it. Simple as that.

[dependencies]
# Is your crate listed here?
serde = "1"

Missing it? Add it in one command (requires Cargo 1.62+):

cargo add serde

Many popular crates โ€” serde, tokio, axum โ€” require feature flags to unlock the parts you actually use:

cargo add serde --features derive
cargo add tokio --features full

After adding, confirm the entry appeared in Cargo.toml, then rebuild:

cargo build

Step 2 โ€” Verify the crate name is exactly right

Crate names use hyphens (-) on crates.io, but underscores (_) inside Rust source. This silent mismatch catches people constantly.

  • In Cargo.toml: my-crate = "0.1"
  • In Rust source: use my_crate::SomeStruct;
# Cargo.toml
[dependencies]
my-crate = "0.1"
// src/main.rs
use my_crate::SomeStruct;  // underscore, not hyphen

A typo in Cargo.toml โ€” even one wrong character โ€” means Cargo downloads nothing and the compiler complains. Cross-check the exact spelling on crates.io before moving on.

Step 3 โ€” Refresh the crate index and lock file

Cargo.lock can fall out of sync, especially after manual edits to Cargo.toml. Force a refresh:

cargo fetch
cargo build

Still broken? Update just the crate causing trouble:

cargo update -p serde

Or blow away all locks and let Cargo resolve fresh:

cargo update

Step 4 โ€” Make sure you're in the right workspace member

Workspaces have a root Cargo.toml and separate member crates. Each member manages its own dependencies โ€” the root doesn't share them automatically.

# workspace root Cargo.toml
[workspace]
members = ["app", "lib"]

If the error comes from app/src/main.rs, check app/Cargo.toml, not the root. Then target that package specifically:

cargo build -p app

Step 5 โ€” Check the Rust edition and extern crate usage

Rust 2015 required explicit extern crate declarations everywhere. Rust 2018 and later dropped that requirement โ€” you just write use directly. Leftover 2015-style declarations in a 2021 project cause confusion.

If your Cargo.toml says edition = "2021", delete lines like:

extern crate serde; // remove this

And write instead:

use serde::Deserialize;

The only cases that still need extern crate today are proc-macro crates and special no_std uses like extern crate alloc;.

Step 6 โ€” The no_std case: can't find crate for std

Writing firmware or WebAssembly and seeing can't find crate for 'std'? Your compilation target has no standard library. Add #![no_std] at the top of your crate root and switch from std to core:

#![no_std]

use core::fmt;
use core::mem;

Alternatively, if you do want std, check whether the right target is installed:

# List installed targets
rustup target list --installed

# Add a target that includes std
rustup target add x86_64-unknown-linux-gnu

Step 7 โ€” Reinstall the Rust toolchain if nothing else works

A corrupted toolchain โ€” often caused by an interrupted rustup update โ€” can make the compiler lose track of std, core, and alloc entirely. Rare, but it happens. Uninstall and reinstall clean:

rustup toolchain uninstall stable
rustup toolchain install stable
rustup component add rustfmt clippy

Then wipe the build cache and start fresh:

cargo clean
cargo build

Verification โ€” confirm the fix worked

Run a clean build and filter the output to what matters:

cargo build 2>&1 | grep -E "error|warning|Compiling"

A healthy build looks like this:

   Compiling serde v1.0.210
   Compiling my-project v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 3.42s

No error[E0463] lines. The crate was found and linked.

Quick reference โ€” common causes and fixes

  • Crate not in Cargo.toml โ†’ run cargo add <crate-name>
  • Typo in crate name โ†’ verify on crates.io, fix spelling
  • Missing features flag โ†’ cargo add tokio --features full
  • Stale lock file โ†’ run cargo fetch or cargo update
  • Wrong workspace member โ†’ check each member's own Cargo.toml
  • Edition mismatch โ†’ remove old extern crate lines for 2018+ edition
  • no_std target โ†’ add #![no_std] or install the right target with rustup
  • Corrupted toolchain โ†’ rustup toolchain uninstall stable && rustup toolchain install stable

Related Error Notes