denoland/deno · error
package name must not contain additional path segments
Error message
package name must not contain additional path segments
What it means
`parse_package_name` in cli/registry.rs splits a fully qualified JSR package name (e.g. `@scope/package`) into its `(scope, package)` parts before talking to the registry API. It first parses the name as a `jsr:<name>@*` requirement reference; if that parse yields a sub-path (e.g. `@scope/pkg/extra` or `@scope/pkg@1.0.0/feature`), the name carries URL path segments beyond the package itself, which the registry publish/lookup flow does not accept, so this error is raised.
Source
Thrown at cli/registry.rs:236
.context("Failed to parse authorization header")?,
);
}
let response = request.send().await?;
Ok(response)
}
/// Splits a fully qualified JSR package name (e.g. `@scope/package`) into its
/// `(scope, package)` parts.
pub fn parse_package_name(name: &str) -> Result<(&str, &str), AnyError> {
// Keep the explicit path-safety checks below even if the JSR grammar changes.
let reference = JsrPackageReqReference::from_str(&format!("jsr:{name}@*"))
.map_err(|_| {
deno_core::anyhow::anyhow!(
"package name must use the '@<scope>/<package>' format"
)
})?;
if reference.sub_path().is_some() {
bail!("package name must not contain additional path segments");
}
let Some((scope, package)) =
name.strip_prefix('@').and_then(|name| name.split_once('/'))
else {
bail!("package name must use the '@<scope>/<package>' format");
};
for component in [scope, package] {
if component == "." || component == ".." {
bail!("package name must not contain dot path segments");
}
if component
.chars()
.any(|c| matches!(c, '/' | '\\' | '?' | '#' | '%'))
{
bail!("package name contains a URL path or delimiter character");
}
}View on GitHub (pinned to f7822238ca)
Solutions
- Remove everything after the package name, keeping only `@<scope>/<package>` (e.g. `@std/path` not `@std/path/join`)
- If you meant to target a specific export, pass the export/sub-path in the field designed for it (import specifier, version requirement, or CLI export argument), not in the package-name field
- Strip any trailing slash or query/fragment before passing the name to the API
Example fix
// before
parse_package_name("@my-scope/my-pkg/utils")?;
// after
parse_package_name("@my-scope/my-pkg")?; Defensive patterns
Strategy: validation
Validate before calling
fn is_bare_jsr_name(name: &str) -> bool {
let Some(rest) = name.strip_prefix('@') else { return false };
match rest.split_once('/') {
Some((scope, pkg)) => !scope.is_empty() && !pkg.is_empty() && !pkg.contains('/'),
None => false,
}
}
if !is_bare_jsr_name(user_name) {
eprintln!("pass only the bare package name, e.g. @scope/pkg");
return;
}
let (scope, package) = parse_package_name(user_name)?; Type guard
fn is_bare_jsr_name(name: &str) -> bool {
name.starts_with('@')
&& name.strip_prefix('@').and_then(|r| r.split_once('/'))
.map(|(s, p)| !s.is_empty() && !p.is_empty() && !p.contains('/'))
.unwrap_or(false)
} Try / catch
match parse_package_name(name) {
Ok((scope, package)) => /* use scope/package */,
Err(e) if e.to_string().contains("additional path segments") => {
eprintln!("strip the sub-path: use the bare @scope/package name");
}
Err(e) => return Err(e),
} Prevention
- Never embed sub-paths or export names in package-name fields; keep them in the import/export specifier
- Strip trailing slashes and query/fragment parts from user-supplied names before validating
- Add a pre-call validator that rejects names with more than one '/'
- Log the raw input before parsing to catch copy-paste of full import specifiers or URLs
When it happens
Trigger: Calling `parse_package_name` with a name containing a sub-path, e.g. `@scope/package/submodule`, `@scope/package/`, or any string that a JsrPackageReqReference parse resolves with a non-None `sub_path()`.
Common situations: Copy-pasting an import specifier like `jsr:@std/path/join` or a URL tail (`@scope/pkg/deep/file.ts`) into a tool flag or config field that expects only the bare package name; scripting publish automation that concatenates an export name onto the package name.
Related errors
- Invalid package name '{}'. Package name must be in the forma
- package name must use the '@<scope>/<package>' format
- package name must not contain dot path segments
- package name contains a URL path or delimiter character
- Must be a file URL
AI-assisted analysis of denoland/deno@f7822238ca (2026-08-29).
Data as JSON: /api/errors/cbb1ad590d39f24f.
Report an issue: GitHub.