astral-sh/uv · error

Package `{package}` not found in workspace

Error message

Package `{package}` not found in workspace

What it means

After `uv build --package <name>`, uv discovers the workspace rooted at the source directory and looks the name up in workspace.packages(). If no member (root package or tool.uv.workspace.members entry) carries that exact project name, this error fires. Lookup is exact-match on the normalized project name from each member's pyproject.toml.

Source

Thrown at crates/uv/src/commands/build_frontend.rs:373

    // If a `--package` or `--all-packages` was provided, adjust the source directory.
    let packages = if let Some(package) = package {
        if matches!(src, Source::File(_)) {
            return Err(anyhow::anyhow!(
                "Cannot specify `--package` when building from a file"
            ));
        }

        let workspace = match workspace {
            Ok(ref workspace) => workspace,
            Err(err) => {
                return Err(err).context("`--package` was provided, but no workspace was found");
            }
        };

        let package = workspace
            .packages()
            .get(package)
            .ok_or_else(|| anyhow::anyhow!("Package `{package}` not found in workspace"))?;

        if !package.pyproject_toml().is_package(true) {
            let name = &package.project().name;
            let pyproject_toml = package.root().join("pyproject.toml");
            return Err(anyhow::anyhow!(
                "Package `{}` is missing a `{}`. For example, to build with `{}`, add the following to `{}`:\n```toml\n[build-system]\nrequires = [\"uv_build>={min_version},<{max_version}\"]\nbuild-backend = \"uv_build\"\n```",
                name.cyan(),
                "build-system".green(),
                "uv_build".cyan(),
                pyproject_toml.user_display().cyan()
            ));
        }

        vec![AnnotatedSource::from(Source::Directory(Cow::Borrowed(
            package.root(),
        )))]
    } else if all_packages {
        if matches!(src, Source::File(_)) {

View on GitHub (pinned to f1a42680ff)

Solutions

  1. List the actual member names (check each pyproject.toml `[project] name` under the workspace root) and correct the --package value.
  2. Add the package's directory to `tool.uv.workspace.members` in the workspace root pyproject.toml if it is meant to be a member.
  3. Run from (or pass `--directory`/`--project` pointing at) the correct workspace root so discovery finds the package.
  4. Use the exact spelling/casing of the project name; avoid distribution-name vs import-name confusion.

Example fix

# before
uv build --package uvcli
# after (member is named `uv-cli` in its pyproject.toml)
uv build --package uv-cli
Defensive patterns

Strategy: validation

Validate before calling

# Rust: verify membership before calling build
let workspace = Workspace::discover(src_dir, &DiscoveryOptions::default(), cache, ws_cache).await?;
let name = PackageName::from_str(package)?;
if !workspace.packages().contains_key(&name) {
    anyhow::bail!("{name} is not a workspace member; members: {:?}",
        workspace.packages().keys().collect::<Vec<_>>());
}

Prevention

When it happens

Trigger: `uv build --package uv-cli` when the member is actually named `uv-cli` but you typed `uvcli` (or a renamed package after a version bump); the target package lives outside the discovered workspace's members list; running from a directory whose workspace root differs from the one containing the package.

Common situations: Package renamed recently and stale scripts use the old name; monorepo where the desired member is excluded from workspace.members; running from a subdirectory that resolves to a different workspace root than expected.

Related errors


AI-assisted analysis of astral-sh/uv@f1a42680ff (2026-08-16). Data as JSON: /api/errors/0571841e29d334dd. Report an issue: GitHub.