yarnpkg/yarn · error · MessageError

tooFewArguments

Error message

tooFewArguments

What it means

`yarn remove` requires at least one package name argument; an empty args array (remove.js:34) throws tooFewArguments with the minimum count (1).

Source

Thrown at src/cli/commands/remove.js:32

const emoji = require('node-emoji');

export const requireLockfile = true;

export function setFlags(commander: Object) {
  commander.description('Removes a package from your direct dependencies updating your package.json and yarn.lock.');
  commander.usage('remove [packages ...] [flags]');
  commander.option('-W, --ignore-workspace-root-check', 'required to run yarn remove inside a workspace root');
}

export function hasWrapper(commander: Object, args: Array<string>): boolean {
  return true;
}

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
  const isWorkspaceRoot = config.workspaceRootFolder && config.cwd === config.workspaceRootFolder;

  if (!args.length) {
    throw new MessageError(reporter.lang('tooFewArguments', 1));
  }

  // running "yarn remove something" in a workspace root is often a mistake
  if (isWorkspaceRoot && !flags.ignoreWorkspaceRootCheck) {
    throw new MessageError(reporter.lang('workspacesRemoveRootCheck'));
  }

  const totalSteps = args.length + 1;
  let step = 0;

  // load manifests
  const lockfile = await Lockfile.fromDirectory(config.lockfileFolder);
  const rootManifests = await config.getRootManifests();
  const manifests = [];

  for (const name of args) {
    reporter.step(++step, totalSteps, `Removing module ${name}`, emoji.get('wastebasket'));

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Provide one or more dependency names: `yarn remove lodash`.
  2. In scripts, guard with `[ "$#" -gt 0 ]` (or check the array length) before invoking `yarn remove`.
  3. Double-check the intended dependency names against package.json `dependencies`.

Example fix

# before
$ yarn remove
# after
$ yarn remove lodash
Defensive patterns

Strategy: validation

Validate before calling

function assertRemoveArgs(args) {
  if (!args || args.length === 0) {
    throw new Error('yarn remove requires at least one package name.');
  }
}

Try / catch

try {
  await runYarn(['remove', ...args]);
} catch (e) {
  if (/tooFewArguments/.test(e.message)) {
    console.error('Provide at least one dependency name to remove.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running bare `yarn remove`, or a script that calls `yarn remove` with no package names (e.g., `yarn remove "$@"` when no args were forwarded).

Common situations: Typing the command without operands; an automation step that conditionally removes packages but forwarded an empty list.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/fc87198b668f1400. Report an issue: GitHub.