FuelLabs/sway · error · anyhow::Error

failed to find package `{}` in {}

Error message

failed to find package `{}` in {}

What it means

Mirror of the git path: after downloading and extracting the IPFS archive into the cache directory, forc searches it for a package whose [project].name equals the dependency key. Nothing found yields this error with the requested name and the cid source.

Source

Thrown at forc-pkg/src/source/ipfs.rs:107

                        }
                        source::IPFSNode::WithUrl(ipfs_node_gateway_url) => {
                            println_action_green(
                                "Fetching",
                                &format!(
                                    "from {ipfs_node_gateway_url}. Note: This can take several minutes."
                                ),
                            );
                            cid.fetch_with_gateway_url(&ipfs_node_gateway_url, &dest)
                                .await
                        }
                    }
                })?;
            }
        }
        let path = {
            let _guard = lock.read()?;
            manifest::find_within(repo_path, ctx.name()).ok_or_else(|| {
                anyhow::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 = pkg_cache_dir(&self.0);
        // Co-ordinate access to the ipfs 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::anyhow!("failed to find package `{}` in {}", name, self))?;
        Ok(source::DependencyPath::ManifestPath(path))
    }
}

View on GitHub (pinned to 47e5e902fa)

Solutions

  1. Inspect the cached extraction under the ipfs cache directory and use the exact [project].name as your dependency key
  2. If the cid itself is wrong, obtain the correct cid from the package maintainer
  3. Delete Forc.lock and re-resolve after fixing the dependency key

Example fix

# before
[dependencies]
tokens = { ipfs = "Qm..." }  # package inside is named "sway_lib_tokens"

# after
[dependencies]
sway_lib_tokens = { ipfs = "Qm..." }
Defensive patterns

Strategy: validation

Validate before calling

use forc_pkg::manifest;

// after fetching the cid content, verify the declared name exists inside it
if manifest::find_within(&ipfs_cache_dir, dep_name).is_none() {
    anyhow::bail!("`{dep_name}` not found inside ipfs content {cid}; check its Forc.toml [project].name");
}

Prevention

When it happens

Trigger: The dependency key in [dependencies] does not match the package name inside the content addressed by the cid; the cid points at a directory that contains no Forc.toml declaring that name.

Common situations: Assuming the cid's project name equals the dependency key; upstream renamed the package while the same cid convention was kept in docs.

Related errors


AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16). Data as JSON: /api/errors/ed6d54c2d24c59c7. Report an issue: GitHub.