yarnpkg/yarn · error · MessageError
missingWhyDependency
Error message
missingWhyDependency
What it means
Thrown at the top of 'yarn why' when no positional argument is supplied. The command needs exactly one dependency query (a package name or pattern) to explain why it is installed.
Source
Thrown at src/cli/commands/why.js:130
commander.description('Identifies why a package has been installed, detailing which other packages depend on it.');
}
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,View on GitHub (pinned to c2dda503f3)
Solutions
- Pass a dependency name: 'yarn why <package>'.
- You may pass a scoped name '@scope/pkg' or a path-style query.
Example fix
# before $ yarn why # after $ yarn why lodash
Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(args) || args.length === 0) {
throw new Error("'yarn why' requires exactly one dependency query argument.");
} Type guard
function hasWhyQuery(args: string[]): boolean {
return Array.isArray(args) && args.length === 1;
} Prevention
- Wrap 'yarn why' in a script that always supplies a query.
- Validate arg count before invoking in automation.
When it happens
Trigger: Running bare 'yarn why' with no arguments, so args.length is 0.
Common situations: User forgot the package name; script/alias invoked 'yarn why' without arguments.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/e5ca43904e0fb8ae.
Report an issue: GitHub.