yarnpkg/yarn · error · MessageError
tooFewArguments
Error message
tooFewArguments
What it means
Thrown by 'yarn unplug' when the --clear flag is supplied but no positional package args are given (args.length === 0). --clear targets specific packages, so omitting them is ambiguous.
Source
Thrown at src/cli/commands/unplug.js:30
export function hasWrapper(commander: Object): boolean {
return true;
}
export function setFlags(commander: Object) {
commander.description(
'Temporarily copies a package (with an optional @range suffix) outside of the global cache for debugging purposes',
);
commander.usage('unplug [packages ...] [flags]');
commander.option('--clear', 'Delete the selected packages');
commander.option('--clear-all', 'Delete all unplugged packages');
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
if (!config.plugnplayEnabled) {
throw new MessageError(reporter.lang('unplugDisabled'));
}
if (!args.length && flags.clear) {
throw new MessageError(reporter.lang('tooFewArguments', 1));
}
if (args.length && flags.clearAll) {
throw new MessageError(reporter.lang('noArguments'));
}
if (flags.clearAll) {
await clearAll(config);
} else if (flags.clear) {
await clearSome(config, new Set(args));
} else if (args.length > 0) {
const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter);
await wrapLifecycle(config, flags, async () => {
const install = new Install(flags, config, reporter, lockfile);
install.linker.unplugged = args;
await install.init();
});
}
View on GitHub (pinned to c2dda503f3)
Solutions
- Add one or more package names: 'yarn unplug --clear <pkg> [<pkg>...]'.
- If you meant to clear all unplugged packages, use '--clear-all' instead of '--clear'.
Example fix
# before $ yarn unplug --clear # after $ yarn unplug --clear lodash # or $ yarn unplug --clear-all
Defensive patterns
Strategy: validation
Validate before calling
if (flags.clear && (!Array.isArray(args) || args.length === 0)) {
throw new Error("'--clear' requires at least one package name; use '--clear-all' to clear everything.");
} Type guard
function hasClearTargets(flags: Object, args: string[]): boolean {
return Boolean(flags.clear) && args.length > 0;
} Prevention
- Distinguish '--clear <pkgs>' from '--clear-all' in documentation and scripts.
- Validate flag/arg combinations in a wrapper script before delegating to Yarn.
When it happens
Trigger: Running 'yarn unplug --clear' with no package names, so the condition (!args.length && flags.clear) is true.
Common situations: User expects --clear to clear everything (that is --clear-all); forgot to list which packages to clear.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/b534e2c536093610.
Report an issue: GitHub.