{"record":{"id":"8509ac248007dced","repo":"pnpm/pnpm","slug":"err-pnpm-latest-with-spec","errorCode":"ERR_PNPM_LATEST_WITH_SPEC","errorMessage":"Specs are not allowed to be used with --latest ({_0})","messagePattern":"Specs are not allowed to be used with --latest \\((.+?)\\)","errorType":"exception","errorClass":"UpdateError::LatestWithSpec","httpStatus":null,"severity":"error","filePath":"pnpm/crates/package-manager/src/update.rs","lineNumber":158,"sourceCode":"    /// materializing `node_modules`. Forwarded to the install.\n    pub lockfile_only: bool,\n    /// Sink notified for each resolved tarball package, and the source of\n    /// the optional resolver-time [`PackageVersionGuard`]. `None` for a\n    /// plain `pacquet update`; `pacquet audit --fix update` installs one\n    /// whose guard rejects vulnerable versions so the resolver falls back\n    /// to a safe one.\n    ///\n    /// [`PackageVersionGuard`]: pnpm_resolving_resolver_base::PackageVersionGuard\n    pub resolution_observer: Option<Arc<dyn crate::ResolutionObserver>>,\n}\n\n/// Error type of [`Update`].\n#[derive(Debug, Display, Error, Diagnostic)]\npub enum UpdateError {\n    /// `--latest` was combined with a versioned selector (`foo@2`).\n    #[display(\"Specs are not allowed to be used with --latest ({_0})\")]\n    #[diagnostic(code(ERR_PNPM_LATEST_WITH_SPEC))]\n    LatestWithSpec(#[error(not(source))] String),\n\n    /// Package selectors were given with `--depth 0` but none matched a\n    /// direct dependency.\n    #[display(\"None of the specified packages were found in the dependencies.\")]\n    #[diagnostic(code(ERR_PNPM_NO_PACKAGE_IN_DEPENDENCIES))]\n    NoPackageInDependencies,\n\n    /// A `--workspace` selector named a dependency that no workspace\n    /// project publishes.\n    #[display(r#\"\"{_0}\" not found in the workspace\"#)]\n    #[diagnostic(code(ERR_PNPM_WORKSPACE_PACKAGE_NOT_FOUND))]\n    WorkspacePackageNotFound(#[error(not(source))] String),\n\n    /// A resolver failed while computing the specifier `--latest` should\n    /// write for a direct dependency.\n    #[display(\"Failed to resolve the latest version of {name}: {error}\")]\n    #[diagnostic(code(ERR_PNPM_PACKAGE_MANAGER_UPDATE_RESOLVE_LATEST))]\n    ResolveLatest {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/pnpm/pnpm/blob/6261b7f388016d57ca6b90340342411cd1d0d00f/pnpm/crates/package-manager/src/update.rs#L140-L176","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"# before\npnpm update --latest lodash@4\n# after\npnpm update --latest lodash","handlingStrategy":"validation","validationCode":"function assertBareSelectors(selectors, latest) {\n  if (!latest) return;\n  for (const sel of selectors) {\n    const at = sel.lastIndexOf('@');\n    if (at > 0) throw new Error('--latest cannot take a version spec: ' + sel);\n  }\n}","typeGuard":"function isBareSelector(selector) {\n  // leading @scope is allowed; a trailing @version is not\n  return selector.lastIndexOf('@') <= 0;\n}","tryCatchPattern":null,"preventionTips":["Treat `pkg@range` and --latest as mutually exclusive when scripting updates.","Validate selectors in wrappers before delegating to pnpm."],"tags":["pnpm","update","cli","arguments"],"backgroundTag":"invalid-cli-argument","analyzedSha":"6261b7f388016d57ca6b90340342411cd1d0d00f","analyzedAt":"2026-08-17T18:30:54.750Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}