{"record":{"id":"c8917b20232eef7f","repo":"astral-sh/uv","slug":"cannot-specify-package-when-building-from-a-fi","errorCode":null,"errorMessage":"Cannot specify `--package` when building from a file","messagePattern":"Cannot specify `--package` when building from a file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/uv/src/commands/build_frontend.rs","lineNumber":358,"sourceCode":"\n    // Limit to the stable version range.\n    let min_version = Version::from_str(uv_version::version()).unwrap();\n    debug_assert!(\n        min_version.release()[0] == 0,\n        \"migrate to major version bumps\"\n    );\n    let max_version = Version::new(\n        [0, min_version.release()[1] + 1]\n            .into_iter()\n            // Add trailing zeroes to match the version length, to use the same style\n            // as `--bounds`.\n            .chain(iter::repeat_n(0, min_version.release().len() - 2)),\n    );\n\n    // If a `--package` or `--all-packages` was provided, adjust the source directory.\n    let packages = if let Some(package) = package {\n        if matches!(src, Source::File(_)) {\n            return Err(anyhow::anyhow!(\n                \"Cannot specify `--package` when building from a file\"\n            ));\n        }\n\n        let workspace = match workspace {\n            Ok(ref workspace) => workspace,\n            Err(err) => {\n                return Err(err).context(\"`--package` was provided, but no workspace was found\");\n            }\n        };\n\n        let package = workspace\n            .packages()\n            .get(package)\n            .ok_or_else(|| anyhow::anyhow!(\"Package `{package}` not found in workspace\"))?;\n\n        if !package.pyproject_toml().is_package(true) {\n            let name = &package.project().name;","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv/src/commands/build_frontend.rs#L340-L376","documentation":"`uv build --package <name>` narrows a workspace build to one member, which only makes sense when the source is a directory. If the resolved source is a file (a sdist archive), uv rejects the combination because --package cannot select inside an archive. The check is a direct Source::File match before workspace lookup.","triggerScenarios":"`uv build --package mypkg ./dist/mypkg-1.0.tar.gz`; passing a .tar.gz/.zip as src while --package is set via CLI or config; scripts that always pass --package accidentally reusing a path that now points at a file.","commonSituations":"A build script shared between directory builds and artifact rebuilds; flags copy-pasted from a workspace invocation into an sdist rebuild command.","solutions":["Drop `--package` when building from a file: the archive already identifies the package.","Or point the source at the package directory (and keep --package) instead of the built archive."],"exampleFix":"# before\nuv build --package mypkg ./dist/mypkg-1.0.tar.gz\n# after\nuv build ./dist/mypkg-1.0.tar.gz      # or: uv build --package mypkg ./crates/mypkg","handlingStrategy":"validation","validationCode":"# Shell: only add --package when the source is a directory\nif [ -d \"$SRC\" ]; then\n  uv build --package \"$PKG\" \"$SRC\"\nelse\n  uv build \"$SRC\"\nfi","typeGuard":"fn supports_package_selection(src: &Source) -> bool {\n    matches!(src, Source::Directory(_))\n}","tryCatchPattern":null,"preventionTips":["Reserve --package for directory/workspace builds; never combine it with archive paths.","Keep CI build matrices separate: one job template for workspace builds, one for artifact rebuilds."],"tags":["build","cli-usage","package-selection"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}