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.
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 enabledCommon 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.
[dependencies]
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }Correct the import path
- Read the
help:/note:lines - they often name the right path or the missing feature. - Confirm the crate is declared in
[dependencies]. - 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 checklocally to catch unresolved imports before CI. - Review changelogs for moved modules when bumping a dependency.