Skip to content
Latchkey

Rust "error[E0433]: failed to resolve" in CI

The compiler hit a path segment it couldn’t resolve - usually a crate or module referenced inline (like rand::random()) that isn’t declared as a dependency or isn’t in scope.

What this error means

cargo build fails with error[E0433]: failed to resolve: use of undeclared crate or module X`, pointing at the path expression. Often paired with E0432 when a use` for the same crate also fails.

cargo output
error[E0433]: failed to resolve: use of undeclared crate or module `rand`
 --> src/main.rs:4:14
  |
4 |     let n = rand::random::<u8>();
  |             ^^^^ use of undeclared crate or module `rand`

Common causes

Crate not declared in Cargo.toml

Referencing rand::... in code requires rand in [dependencies]. Without it, the crate name doesn’t resolve at all.

Module path wrong or not brought into scope

A typo in the path, a missing mod declaration, or a private module makes the inline path unresolvable even when the crate is present.

How to fix it

Add the missing dependency

Declare the crate so its name resolves, then rebuild.

Terminal
cargo add rand
# or edit Cargo.toml:
# [dependencies]
# rand = "0.8"

Fix the path or declare the module

  1. Confirm the crate name and version exist (cargo search <name>).
  2. For your own modules, ensure a mod foo; declaration and correct visibility.
  3. Use the full path the error suggests, or add a use to bring it into scope.

How to prevent it

  • Declare every crate you reference in [dependencies] (or use cargo add).
  • Keep mod declarations and module visibility correct.
  • Run cargo check before pushing to catch resolution errors.

Related guides

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