pnpm/pnpm · error · UpdateError::LatestWithSpec
ERR_PNPM_LATEST_WITH_SPEC
ERR_PNPM_LATEST_WITH_SPEC
Error message
Specs are not allowed to be used with --latest ({_0}) What it means
`pnpm update --latest` re-resolves each named dependency to the newest version the registry offers, so a selector that already carries a version spec (`foo@2`) contradicts the flag. Update parses CLI selectors into name pattern plus optional version part and rejects `name@range` combined with --latest with ERR_PNPM_LATEST_WITH_SPEC, rather than guessing which instruction wins.
Source
Thrown at pnpm/crates/package-manager/src/update.rs:158
/// materializing `node_modules`. Forwarded to the install.
pub lockfile_only: bool,
/// Sink notified for each resolved tarball package, and the source of
/// the optional resolver-time [`PackageVersionGuard`]. `None` for a
/// plain `pacquet update`; `pacquet audit --fix update` installs one
/// whose guard rejects vulnerable versions so the resolver falls back
/// to a safe one.
///
/// [`PackageVersionGuard`]: pnpm_resolving_resolver_base::PackageVersionGuard
pub resolution_observer: Option<Arc<dyn crate::ResolutionObserver>>,
}
/// Error type of [`Update`].
#[derive(Debug, Display, Error, Diagnostic)]
pub enum UpdateError {
/// `--latest` was combined with a versioned selector (`foo@2`).
#[display("Specs are not allowed to be used with --latest ({_0})")]
#[diagnostic(code(ERR_PNPM_LATEST_WITH_SPEC))]
LatestWithSpec(#[error(not(source))] String),
/// Package selectors were given with `--depth 0` but none matched a
/// direct dependency.
#[display("None of the specified packages were found in the dependencies.")]
#[diagnostic(code(ERR_PNPM_NO_PACKAGE_IN_DEPENDENCIES))]
NoPackageInDependencies,
/// A `--workspace` selector named a dependency that no workspace
/// project publishes.
#[display(r#""{_0}" not found in the workspace"#)]
#[diagnostic(code(ERR_PNPM_WORKSPACE_PACKAGE_NOT_FOUND))]
WorkspacePackageNotFound(#[error(not(source))] String),
/// A resolver failed while computing the specifier `--latest` should
/// write for a direct dependency.
#[display("Failed to resolve the latest version of {name}: {error}")]
#[diagnostic(code(ERR_PNPM_PACKAGE_MANAGER_UPDATE_RESOLVE_LATEST))]
ResolveLatest {View on GitHub (pinned to 6261b7f388)
Solutions
- Drop the version part: `pnpm update --latest lodash`.
- Keep the spec and drop --latest to update within the declared range: `pnpm update lodash@4`.
Example fix
# before pnpm update --latest lodash@4 # after pnpm update --latest lodash
Defensive patterns
Strategy: validation
Validate before calling
function assertBareSelectors(selectors, latest) {
if (!latest) return;
for (const sel of selectors) {
const at = sel.lastIndexOf('@');
if (at > 0) throw new Error('--latest cannot take a version spec: ' + sel);
}
} Type guard
function isBareSelector(selector) {
// leading @scope is allowed; a trailing @version is not
return selector.lastIndexOf('@') <= 0;
} Prevention
- Treat `pkg@range` and --latest as mutually exclusive when scripting updates.
- Validate selectors in wrappers before delegating to pnpm.
When it happens
Trigger: Run `pnpm update --latest lodash@4`, `pnpm update --latest foo@^2 -D`, or any update invocation where a selector contains an `@` plus a version/range while --latest is set.
Common situations: Copy-pasting the `pnpm add pkg@version` habit into update --latest; upgrade scripts that interpolate pinned versions into the update command; mixing 'upgrade one package to latest' with stale pinned arguments.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
AI-assisted analysis of pnpm/pnpm@6261b7f388 (2026-08-17).
Data as JSON: /api/errors/8509ac248007dced.
Report an issue: GitHub.