FuelLabs/sway · error · anyhow::Error
failed to find package `{}` in {}
Error message
failed to find package `{}` in {} What it means
After fetching a git dependency repo, forc searches it with manifest::find_within for a package whose Forc.toml declares the dependency's name. This error means the repo fetched fine but contains no package with that name - the key in [dependencies] must match the dependency's own [project].name, not the repo name.
Source
Thrown at forc-pkg/src/source/git/mod.rs:219
// probably fine for most cases as users should never be touching these
// directories, however we should add some code to validate this. E.g. can we
// recreate the git hash by hashing the directory or something along these lines
// using git?
// https://github.com/FuelLabs/sway/issues/7075
{
let _guard = lock.write()?;
if !repo_path.exists() {
println_action_green(
"Fetching",
&format!("{} {}", ansiterm::Style::new().bold().paint(ctx.name), self),
);
fetch(ctx.fetch_id(), ctx.name(), self)?;
}
}
let path = {
let _guard = lock.read()?;
manifest::find_within(repo_path, ctx.name())
.ok_or_else(|| anyhow!("failed to find package `{}` in {}", ctx.name(), self))?
};
PackageManifestFile::from_file(path)
}
}
impl source::DepPath for Pinned {
fn dep_path(&self, name: &str) -> anyhow::Result<source::DependencyPath> {
let repo_path = commit_path(name, &self.source.repo, &self.commit_hash);
// Co-ordinate access to the git checkout directory using an advisory file lock.
let lock = forc_util::path_lock(&repo_path)?;
let _guard = lock.read()?;
let path = manifest::find_within(&repo_path, name)
.ok_or_else(|| anyhow!("failed to find package `{}` in {}", name, self))?;
Ok(source::DependencyPath::ManifestPath(path))
}
}
impl fmt::Display for Url {View on GitHub (pinned to 47e5e902fa)
Solutions
- Open the fetched repo (under ~/.forc/git/checkouts) and read its Forc.toml [project] name; use exactly that string as your dependency key
- If the repo hosts several packages, depend on the specific member's name
- Delete Forc.lock and re-resolve after fixing the dependency key
Example fix
# before
[dependencies]
foo = { git = "https://github.com/org/foo", tag = "v1.0.0" }
# but the repo's package is named "foo-core"
# after
[dependencies]
foo-core = { git = "https://github.com/org/foo", tag = "v1.0.0" } Defensive patterns
Strategy: validation
Validate before calling
use forc_pkg::manifest;
// after a manual clone/fetch, confirm the declared name exists before building
let found = manifest::find_within(&repo_checkout_dir, dep_name);
if found.is_none() {
anyhow::bail!("dependency name `{dep_name}` not present in {repo_url}; check its Forc.toml [project].name");
} Prevention
- Always read the dependency repo's [project].name before adding the dependency key
- Prefer official dependency snippets from the repo's own README
- Delete Forc.lock after renaming dependency keys so names re-resolve
When it happens
Trigger: Declaring e.g. name = "sway-lib-std" while the repo's package is actually named "std"; the repo is a monorepo whose members have different names than the repository; the package was renamed upstream after you pinned it.
Common situations: Copy-pasting dependency snippets from docs where the key differs from the real package name; assuming the GitHub repo name is the package name.
Related errors
- the dependency `{}` could not be found in `{}`
- dependency of {:?} named {:?} is invalid: {}
- failed to find package `{}` in {}
- failed to write toml file: {}
- hex salt declaration needs to start with 0x
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/22ede3204812273d.
Report an issue: GitHub.