{"record":{"id":"913d1ffb7e998d64","repo":"pnpm/pnpm","slug":"pkg-unknown-subcommand","errorCode":"PKG_UNKNOWN_SUBCOMMAND","errorMessage":"Unknown subcommand \"${subcmd}\"","messagePattern":"Unknown subcommand \"(.+?)\"","errorType":"error_code","errorClass":"PnpmError","httpStatus":null,"severity":"error","filePath":"pnpm11/pkg-manifest/commands/src/pkg.ts","lineNumber":66,"sourceCode":"  if (opts.recursive) {\n    return handleRecursiveCommand(opts, subcmd, args)\n  }\n\n  return runSubcommand(opts, subcmd, args)\n}\n\nasync function runSubcommand (opts: PkgCommandOptions, subcmd: string, args: string[]): Promise<string | void> {\n  switch (subcmd) {\n    case 'get':\n      return pkgGet(opts, args)\n    case 'set':\n      return pkgSet(opts, args)\n    case 'delete':\n      return pkgDelete(opts, args)\n    case 'fix':\n      return pkgFix(opts)\n    default:\n      throw new PnpmError('PKG_UNKNOWN_SUBCOMMAND', `Unknown subcommand \"${subcmd}\"`, {\n        hint: help(),\n      })\n  }\n}\n\nasync function handleRecursiveCommand (opts: PkgCommandOptions, subcmd: string, args: string[]): Promise<string | void> {\n  const workspaceDir = opts.workspaceDir\n  if (!workspaceDir) {\n    throw new PnpmError('PKG_RECURSIVE_NO_ROOT', 'Cannot run recursively outside of a workspace')\n  }\n\n  const selectedProjects = opts.selectedProjectsGraph == null\n    ? []\n    : Object.values(opts.selectedProjectsGraph)\n\n  if (selectedProjects.length === 0) {\n    throw new PnpmError('PKG_RECURSIVE_NO_PACKAGES', 'No workspace packages were selected')\n  }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/pnpm/pnpm/blob/6261b7f388016d57ca6b90340342411cd1d0d00f/pnpm11/pkg-manifest/commands/src/pkg.ts#L48-L84","documentation":"Thrown by the `pnpm pkg` command when its first positional argument is not one of the supported subcommands: `get`, `set`, `delete`, or `fix`. `runSubcommand`'s switch falls through to the default branch and raises this error with the full help text attached as a hint. It exists to catch typos and npm-style guesses before any manifest is read or written.","triggerScenarios":"Running `pnpm pkg <anything-other-than-get/set/delete/fix>`, e.g. `pnpm pkg del name` (wrong abbreviation), `pnpm pkg list`, or `pnpm pkg instal`. Also hit when a wrapper script passes an empty or mis-ordered first parameter so the subcommand token is missing or swallowed by a flag.","commonSituations":"Typo'ing `delete` as `del`/`remove`/`rm`; assuming npm-style subcommands like `list` exist; older pnpm releases that lack the `fix` subcommand; CI scripts that assemble the `pnpm pkg` argv dynamically.","solutions":["Run `pnpm pkg help` and use one of the exact subcommands: get, set, delete, fix","Fix the abbreviation - the remove subcommand is `delete`, not `del` or `remove`","To read fields use `pnpm pkg get` (optionally with dotted key paths), not `list`","Upgrade pnpm if `pnpm pkg fix` is reported as unknown on an old release"],"exampleFix":"# before\npnpm pkg del name\n\n# after\npnpm pkg delete name","handlingStrategy":"validation","validationCode":"const PKG_SUBCOMMANDS = new Set(['get', 'set', 'delete', 'fix'])\n\nif (!PKG_SUBCOMMANDS.has(subcmd)) {\n  console.error(`unknown pkg subcommand: ${subcmd}. Valid: get, set, delete, fix`)\n  process.exitCode = 1\n} else {\n  await handler(opts, [subcmd, ...args])\n}","typeGuard":"type PkgSubcommand = 'get' | 'set' | 'delete' | 'fix'\n\nconst isPkgSubcommand = (s: string): s is PkgSubcommand =>\n  s === 'get' || s === 'set' || s === 'delete' || s === 'fix'","tryCatchPattern":"try {\n  await runPnpm(['pkg', subcmd, ...args])\n} catch (err) {\n  if (err?.code === 'ERR_PNPM_PKG_UNKNOWN_SUBCOMMAND') {\n    // print command help instead of a stack trace\n  } else throw err\n}","preventionTips":["Validate the subcommand against get/set/delete/fix before invoking `pnpm pkg`","In shell scripts use `set -u` and quote every argument so an unset variable never shifts the subcommand position","Pin the pnpm version in CI so a subcommand present locally cannot be missing in the pipeline"],"tags":["pnpm-pkg","cli","subcommand","typo","manifest"],"backgroundTag":"unknown-cli-subcommand","analyzedSha":"6261b7f388016d57ca6b90340342411cd1d0d00f","analyzedAt":"2026-08-17T18:30:54.750Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}