Skip to content
Latchkey

Rust "error[E0432]: unresolved import" in CI

A use statement names a path the compiler can’t resolve. The crate or module isn’t there, the path is wrong, or the item lives behind a feature flag you didn’t enable.

What this error means

cargo build fails with error[E0432]: unresolved import X`, pointing at the use` line and often suggesting a similar path. The program does not compile.

cargo output
error[E0432]: unresolved import `tokio::fs`
 --> src/main.rs:1:5
  |
1 | use tokio::fs;
  |     ^^^^^^^^^ no `fs` in the root
  = help: a similar name exists in the module: `io`
  = note: the `fs` module requires feature `fs` to be enabled

Diagnose it: linker, target, or memory

Rust build failures in CI that are not compiler errors are usually a missing system linker or library, a target that is not installed, or the compiler being killed for memory.

Terminal
rustup target list --installed
cc --version || echo "no C toolchain: install build-essential"
free -h

# exit 137 during codegen is an out-of-memory kill, not a compile error
cargo build -j 2   # fewer parallel codegen units uses less memory

Common causes

A feature-gated module isn’t enabled

Crates like tokio put modules behind features. use tokio::fs; fails unless the fs feature is enabled in Cargo.toml, even though the crate is present.

Wrong path, missing crate, or renamed item

A typo in the module path, a crate not declared in Cargo.toml, or an item moved/renamed in a newer version all leave the use path unresolvable.

How to fix it

Enable the required feature

When the note says a feature is required, enable it on the dependency.

Cargo.toml
[dependencies]
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }

Correct the import path

  1. Read the help:/note: lines - they often name the right path or the missing feature.
  2. Confirm the crate is declared in [dependencies].
  3. For an upgraded crate, check its docs for moved or renamed modules.

How to prevent it

  • Enable the crate features your imports depend on in Cargo.toml.
  • Run cargo check locally to catch unresolved imports before CI.
  • Review changelogs for moved modules when bumping a dependency.

Frequently asked questions

What causes Rust "error[E0432]: unresolved import" in CI?
There are 2 common causes: a feature-gated module isn’t enabled and wrong path, missing crate, or renamed item. Crates like tokio put modules behind features.
How do I fix Rust "error[E0432]: unresolved import" in CI?
There are 2 fixes depending on which cause you have: enable the required feature and correct the import path. Work through them in order, since the first is the most common.
What does Rust "error[E0432]: unresolved import" in CI actually mean?
cargo build fails with error[E0432]: unresolved import X, pointing at the use line and often suggesting a similar path.
How do I stop Rust "error[E0432]: unresolved import" in CI happening again?
Enable the crate features your imports depend on in Cargo.toml. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card