yarnpkg/yarn · error · MessageError
tooManyArguments
Error message
tooManyArguments
What it means
Thrown by 'yarn why' when more than one positional argument is given. The command accepts exactly one dependency query; extra arguments are rejected.
Source
Thrown at src/cli/commands/why.js:133
export function hasWrapper(commander: Object, args: Array<string>): boolean {
return true;
}
// to conform to the current standard '#' as package tree separator
function toStandardPathString(pathString: string): string {
const str = pathString.replace(/\//g, '#');
if (str[0] === '#') {
return str.slice(1);
}
return str;
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
if (!args.length) {
throw new MessageError(reporter.lang('missingWhyDependency'));
}
if (args.length > 1) {
throw new MessageError(reporter.lang('tooManyArguments', 1));
}
const query = await cleanQuery(config, args[0]);
reporter.step(1, 4, reporter.lang('whyStart', args[0]), emoji.get('thinking_face'));
// init
reporter.step(2, 4, reporter.lang('whyInitGraph'), emoji.get('truck'));
const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter);
const install = new Install(flags, config, reporter, lockfile);
const {requests: depRequests, patterns, workspaceLayout} = await install.fetchRequestFromCwd();
await install.resolver.init(depRequests, {
isFlat: install.flags.flat,
isFrozen: install.flags.frozenLockfile,
workspaceLayout,
});
const hoisted = await install.linker.getFlatHoistedTree(patterns);
View on GitHub (pinned to c2dda503f3)
Solutions
- Query one package at a time: 'yarn why foo', then 'yarn why bar'.
- If you passed flags, put them before the query or ensure they are recognized as flags.
Example fix
# before $ yarn why foo bar # after $ yarn why foo
Defensive patterns
Strategy: validation
Validate before calling
if (args.length > 1) {
throw new Error("'yarn why' accepts exactly one argument; query packages one at a time.");
} Type guard
function isSingleQuery(args: string[]): boolean {
return Array.isArray(args) && args.length === 1;
} Prevention
- Pass flags before the query to avoid them being parsed as positional args.
- Loop over packages in a wrapper script if you need to query several.
When it happens
Trigger: Running 'yarn why foo bar' (two or more args), so args.length > 1.
Common situations: User expects to query multiple packages at once; trailing flags parsed as positional args due to ordering.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/6512c83ab1dfcff7.
Report an issue: GitHub.