FuelLabs/sway · error

cannot find dependency in the workspace

Error message

cannot find dependency in the workspace

What it means

dep_path classified the dependency as DependencyPath::Member - the node is expected to be a workspace member - but scanning manifests.values() found no member whose project.name equals the dependency name. The member is missing, renamed, or was never loaded into MemberManifestFiles.

Source

Thrown at forc-pkg/src/pkg.rs:1115

                            }
                        }
                    }
                }
            }

            bail!(
                "no dependency or patch with name {:?} in manifest of {:?}",
                dep_name,
                node_manifest.project.name
            )
        }
        source::DependencyPath::Member => {
            // If a node has a root dependency it is a member of the workspace.
            manifests
                .values()
                .find(|manifest| manifest.project.name == *dep_name)
                .map(|manifest| manifest.path().to_path_buf())
                .ok_or_else(|| anyhow!("cannot find dependency in the workspace"))
        }
    }
}

/// Remove the given set of dependency edges from the `graph`.
///
/// Also removes all nodes that are no longer connected to any root node as a result.
fn remove_deps(
    graph: &mut Graph,
    member_names: &HashSet<String>,
    edges_to_remove: &BTreeSet<EdgeIx>,
) {
    // Retrieve the project nodes for workspace members.
    let member_nodes: HashSet<_> = member_nodes(graph)
        .filter(|&n| member_names.contains(&graph[n].name.to_string()))
        .collect();

    // Before removing edges, sort the nodes in order of dependency for the node removal pass.

View on GitHub (pinned to 47e5e902fa)

Solutions

  1. Make the dependency key exactly equal the member's [project] name.
  2. Ensure the member directory is listed in [workspace] members and contains a valid Forc.toml.
  3. Rebuild so the workspace is re-scanned.

Example fix

# before
# root Forc.toml
[workspace]
members = ["libs/my_lib"]
[dependencies]
my-lib = { path = "libs/my_lib" }

# after
[dependencies]
my_lib = { path = "libs/my_lib" }  # must equal the member's [project] name
Defensive patterns

Strategy: validation

Validate before calling

let member_names: std::collections::HashSet<&str> =
    member_manifests.values().map(|m| m.project.name.as_str()).collect();
for dep_name in parent_manifest.dep_names() {
    if is_workspace_member_ref(dep_name) && !member_names.contains(dep_name) {
        return Err(format!("dependency '{dep_name}' does not match any workspace member name"));
    }
}

Type guard

fn dependency_matches_member(name: &str, manifests: &forc_pkg::MemberManifestFiles) -> bool {
    manifests.values().any(|m| m.project.name == name)
}

Prevention

When it happens

Trigger: A Forc.toml [dependencies] entry uses a name that differs from the member's actual [project] name (including casing); the member directory was removed but still referenced; the member dir is not listed in [workspace] members so its manifest was never loaded.

Common situations: Renaming a member package without updating the dependents' dependency keys; adding a new member folder but forgetting the members entry; name typos between dependency key and member name.

Related errors


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