nodejs/node · error · Error
Must provide a package name to remove
Error message
Must provide a package name to remove
What it means
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.
Source
Thrown at deps/npm/lib/commands/uninstall.js:22
const resolveAllowScripts = require('../utils/resolve-allow-scripts.js')
const completion = require('../utils/installed-shallow.js')
const ArboristWorkspaceCmd = require('../arborist-cmd.js')
class Uninstall extends ArboristWorkspaceCmd {
static description = 'Remove a package'
static name = 'uninstall'
static params = ['save', 'global', ...super.params]
static usage = ['[<@scope>/]<pkg>...']
static ignoreImplicitWorkspace = false
static async completion (opts, npm) {
return completion(npm, opts)
}
async exec (args) {
if (!args.length) {
if (!this.npm.global) {
throw new Error('Must provide a package name to remove')
} else {
try {
const { content: pkg } = await pkgJson.normalize(this.npm.localPrefix)
args.push(pkg.name)
} catch (er) {
if (er.code !== 'ENOENT' && er.code !== 'ENOTDIR') {
throw er
} else {
throw this.usageError()
}
}
}
}
// the /path/to/node_modules/..
const path = this.npm.global
? resolve(this.npm.globalDir, '..')
: this.npm.localPrefixView on GitHub (pinned to 1b2de5e052)
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.
Example fix
// before npm uninstall // after npm uninstall lodash
Defensive patterns
Strategy: validation
Validate before calling
if (!args.length && !npm.global) {
throw new Error('npm uninstall requires at least one package name (or -g to use package.json#name)')
} Type guard
const hasUninstallTarget = (args, isGlobal, pkgName) => args.length > 0 || (isGlobal && Boolean(pkgName))
Try / catch
try {
await uninstall.exec(args)
} catch (err) {
if (/Must provide a package name/i.test(err.message)) {
// surface a usage prompt to the user instead of crashing
} else { throw err }
} Prevention
- 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.
When it happens
Trigger: Running `npm uninstall` with no package arguments while not in `--global` (or `-g`) mode. Also when shell aliases strip arguments.
Common situations: Typo or truncated command; an automation script variable that expanded to empty; running uninstall expecting an interactive picker (npm does not provide one).
Related errors
- ${this.constructor.providerEntity} must be specified in the
- GitLab CI/CD pipeline file must be just a file not a path
- Package name must be specified either as an argument or in t
- Package name must be specified either as an argument or in t
- ID of the trusted relationship to revoke must be specified w
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/2ed4731d695673d2.
Report an issue: GitHub.