{"record":{"id":"2ed4731d695673d2","repo":"nodejs/node","slug":"must-provide-a-package-name-to-remove","errorCode":null,"errorMessage":"Must provide a package name to remove","messagePattern":"Must provide a package name to remove","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/uninstall.js","lineNumber":22,"sourceCode":"const resolveAllowScripts = require('../utils/resolve-allow-scripts.js')\nconst completion = require('../utils/installed-shallow.js')\nconst ArboristWorkspaceCmd = require('../arborist-cmd.js')\n\nclass Uninstall extends ArboristWorkspaceCmd {\n  static description = 'Remove a package'\n  static name = 'uninstall'\n  static params = ['save', 'global', ...super.params]\n  static usage = ['[<@scope>/]<pkg>...']\n  static ignoreImplicitWorkspace = false\n\n  static async completion (opts, npm) {\n    return completion(npm, opts)\n  }\n\n  async exec (args) {\n    if (!args.length) {\n      if (!this.npm.global) {\n        throw new Error('Must provide a package name to remove')\n      } else {\n        try {\n          const { content: pkg } = await pkgJson.normalize(this.npm.localPrefix)\n          args.push(pkg.name)\n        } catch (er) {\n          if (er.code !== 'ENOENT' && er.code !== 'ENOTDIR') {\n            throw er\n          } else {\n            throw this.usageError()\n          }\n        }\n      }\n    }\n\n    // the /path/to/node_modules/..\n    const path = this.npm.global\n      ? resolve(this.npm.globalDir, '..')\n      : this.npm.localPrefix","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/uninstall.js#L4-L40","documentation":"Thrown by `npm uninstall` when invoked with no arguments in non-global mode. Locally, npm cannot guess what to remove (global mode falls back to the local package.json name, but local mode requires an explicit target). The error precedes any arborist work.","triggerScenarios":"Running `npm uninstall` with no package arguments while not in `--global` (or `-g`) mode. Also when shell aliases strip arguments.","commonSituations":"Typo or truncated command; an automation script variable that expanded to empty; running uninstall expecting an interactive picker (npm does not provide one).","solutions":["Name the package(s): `npm uninstall lodash express`.","If you meant to remove the current package's dependencies globally, use `-g` and run from the package dir so it can fall back to package.json name.","Check your shell alias / CI step did not drop the arguments."],"exampleFix":"// before\nnpm uninstall\n// after\nnpm uninstall lodash","handlingStrategy":"validation","validationCode":"if (!args.length && !npm.global) {\n  throw new Error('npm uninstall requires at least one package name (or -g to use package.json#name)')\n}","typeGuard":"const hasUninstallTarget = (args, isGlobal, pkgName) =>\n  args.length > 0 || (isGlobal && Boolean(pkgName))","tryCatchPattern":"try {\n  await uninstall.exec(args)\n} catch (err) {\n  if (/Must provide a package name/i.test(err.message)) {\n    // surface a usage prompt to the user instead of crashing\n  } else { throw err }\n}","preventionTips":["Always specify package names explicitly in scripts.","Validate that an args array is non-empty before invoking uninstall.","Don't alias `npm uninstall` to a form that can drop arguments."],"tags":["validation","uninstall","cli-args"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}