FuelLabs/sway · error

the dependency ` ` could not be found in

Error message

the dependency `{}` could not be found in `{}`

What it means

remove_deps_manifest_table removes entries from a section of Forc.toml ([dependencies] or [contract-dependencies]). The quoted branch fires when the whole section table is absent from the manifest (doc[section_name].as_table_mut() returns None); the same message is also bailed just below for a present section that lacks one of the named keys. Either way, the manifest does not contain what forc remove was asked to remove.

Solutions

  1. Open Forc.toml and confirm the exact key exists under the expected section before removing.
  2. Use the flag matching the section: forc remove --contract-dependency <name> for contract deps, plain forc remove <name> for libraries.
  3. If the section genuinely does not exist, there is nothing to remove - delete the entry manually or skip.
  4. Check spelling and hyphenation of the dependency key as written in the manifest.

Example fix

# before: forc remove foo  but Forc.toml has only
[contract-dependencies]
foo = { ... }

# after: target the right section
$ forc remove --contract-dependency foo
Defensive patterns

Strategy: validation

Validate before calling

// Rust/shell, verify section and key exist before invoking forc remove:
// shell:
//   grep -q '^\[dependencies\]$' Forc.toml && grep -q '^foo *= ' Forc.toml
// Rust: parse the manifest with toml_edit and assert doc["dependencies"][name].is_some().

Try / catch

// anyhow Result - inspect and guide:
match remove_deps(...) {
    Err(e) if e.to_string().contains("could not be found") =>
        eprintln!("check the section ([dependencies] vs [contract-dependencies]) and key spelling"),
    other => other.unwrap(),
}

Prevention

When it happens

Trigger: Running forc remove <pkg> when Forc.toml has no [dependencies] table at all, or the dependency key exists only under a different section (e.g. contract-dependencies) or with a different spelling; the contract-deps variant hits the same guard for [contract-dependencies].

Common situations: Typo'd dependency names; wrong section (plain dep vs contract dep) because the matching flag was not passed; manifests where the section was already cleaned; running remove in the wrong project directory.

Related errors


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

Appendix: source

Thrown at forc-pkg/src/manifest/dep_modifier.rs:358

                    }
                    Dependency::Detailed(details) => {
                        let mut inline = generate_table(details);
                        inline.insert("salt", Value::from(format!("0x{salt}")));
                        Item::Value(toml_edit::Value::InlineTable(inline))
                    }
                };
                table.insert(&dep_name, item);
            }
        };

        Ok(())
    }

    pub fn remove_deps_manifest_table(self, doc: &mut DocumentMut, deps: &[&str]) -> Result<()> {
        let section_name = self.to_string();

        let section_table = doc[section_name.as_str()].as_table_mut().ok_or_else(|| {
            anyhow!(
                "the dependency `{}` could not be found in `{}`",
                deps.join(", "),
                section_name,
            )
        })?;

        match self {
            Section::Deps => {
                for dep in deps {
                    if !section_table.contains_key(dep) {
                        bail!(
                            "the dependency `{}` could not be found in `{}`",
                            dep,
                            section_name
                        );
                    }
                    section_table.remove(dep);
                }

View on GitHub (pinned to 47e5e902fa)