Rust Build Breaks After "default-features = false" in CI
Setting default-features = false on a dependency turns off its entire default feature set - including features your code relied on. The build now fails on a missing module, type, or method that lived behind a default feature you didn’t re-enable.
What this error means
After someone trims a dependency with default-features = false (often to shrink a binary or support no_std), the build fails with an unresolved import, a missing trait impl, or cannot find for an item that used to be available. Reverting the flag, or re-adding the feature, fixes it.
error[E0432]: unresolved import `chrono::serde`
--> src/model.rs:1:5
|
1 | use chrono::serde::ts_seconds;
| ^^^^^^^^^^^^^ no `serde` in `chrono`
= note: `chrono` was added with `default-features = false`; the `serde` feature is offCommon causes
A relied-on feature was in the defaults
Many crates put std, serde, or codec support in their default features. Disabling defaults removes those, so code depending on them no longer compiles.
Trimming features without re-adding the needed ones
default-features = false is meant to be paired with an explicit features = [...]. Omitting the features you actually use leaves the dependency too bare.
How to fix it
Re-enable the specific features you need
Keep defaults off but explicitly list the features your code uses.
[dependencies]
chrono = { version = "0.4", default-features = false, features = ["serde", "clock"] }Check the crate’s default feature set
- Read the crate’s docs.rs feature-flags page to see what
defaultincludes. - Add back exactly the features your code depends on via
features = [...]. - Run
cargo build(andcargo build --no-default-featuresif you target no_std) to confirm.
How to prevent it
- Always pair
default-features = falsewith an explicitfeatures = [...]. - Consult the crate’s default feature list before disabling defaults.
- Test both default and minimal feature builds in CI.