rust-lang/cargo · error · anyhow::Error
the crate ` ` could not be found at
Error message
the crate `{dependency}` could not be found at `{source}` What it means
Thrown by cargo_add's select_package after querying the registry/path/git source for a dependency and receiving zero Candidate summaries. The dependency's source was already resolved (the expect proves it), but no index entry matched the crate name at that source. This is the 'add' analog of a 404: the name does not exist where you told cargo to look.
Solutions
- Verify the package name spelling matches the `name` field in the source's Cargo.toml, not the directory or git URL.
- For --path, confirm the path points at the directory containing the crate's Cargo.toml (not a parent or sibling).
- For --git, list packages in the repo first: `cargo add --git <url>` and, if multiple, append the exact package name as shown in the disambiguation hint.
- If using a custom registry, check the crate is published there (`cargo search <name> --registry <name>`) and that the registry index is up to date.
Example fix
// before cargo add mycrate --path ./sibling // after (path containing Cargo.toml) cargo add mycrate --path ./sibling/mycrate
Defensive patterns
Strategy: validation
Validate before calling
// Before calling cargo add programmatically, confirm the source contains the crate.
use std::path::Path;
fn path_has_crate(dir: &Path, name: &str) -> bool {
let manifest = dir.join("Cargo.toml");
std::fs::read_to_string(manifest)
.map(|t| t.contains(&format!("name = \"{name}\"")))
.unwrap_or(false)
} Prevention
- Always confirm the source directory/git repo actually contains a Cargo.toml with the expected package name before adding.
- Prefer `cargo add --git <url> <exact-package-name>` over bare URL adds.
- In scripts, resolve the package name from metadata before invoking `cargo add`.
When it happens
Trigger: Running `cargo add <name> --path <dir>` or `--git <url>` where the directory/repository contains no package with that name, or `cargo add <name>` against a private/alternate registry that does not index the crate. Also triggered by a typo in the crate name passed to a path/git source, or by pointing --path at a subdirectory that lacks Cargo.toml.
Common situations: Renaming a crate in the source repo but adding it by its old name; pointing --git at a monorepo and forgetting the package lives in a subdir; using a sparse/git registry mirror that has not yet replicated the crate; network/registry-index fetch silently returning an empty result set.
Related errors
- unexpectedly found multiple copies of crate
- multiple packages found at
- all versions of crate
- can't checkout from ' ': you are in the offline mode ( )
- cannot add ` ` as a dependency to itself
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/c3c5a2b2fa2bdf64.
Report an issue: GitHub.
Appendix: source
Thrown at src/ops/cargo_add/mod.rs:1033
}
MaybeWorkspace::Other(query) => {
let possibilities =
crate::util::block_on(registry.query_vec(&query, QueryKind::Normalized))?;
let possibilities: Vec<_> = possibilities
.into_iter()
.filter_map(|s| match s {
IndexSummary::Candidate(s) => Some(s),
_ => None,
})
.collect();
match possibilities.len() {
0 => {
let source = dependency
.source()
.expect("source should be resolved before here");
anyhow::bail!("the crate `{dependency}` could not be found at `{source}`")
}
1 => {
let mut dep = Dependency::from(&possibilities[0]);
if let Some(reg_name) = dependency.registry.as_deref() {
dep = dep.set_registry(reg_name);
}
if let Some(Source::Path(PathSource { base, .. })) = dependency.source() {
if let Some(Source::Path(dep_src)) = &mut dep.source {
dep_src.base = base.clone();
}
}
Ok(dep)
}
_ => {
let source = dependency
.source()
.expect("source should be resolved before here");
anyhow::bail!(View on GitHub (pinned to 98a09e7e7d)