{"record":{"id":"e5ca43904e0fb8ae","repo":"yarnpkg/yarn","slug":"missingwhydependency","errorCode":null,"errorMessage":"missingWhyDependency","messagePattern":"missingWhyDependency","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/why.js","lineNumber":130,"sourceCode":"  commander.description('Identifies why a package has been installed, detailing which other packages depend on it.');\n}\n\nexport function hasWrapper(commander: Object, args: Array<string>): boolean {\n  return true;\n}\n\n// to conform to the current standard '#' as package tree separator\nfunction toStandardPathString(pathString: string): string {\n  const str = pathString.replace(/\\//g, '#');\n  if (str[0] === '#') {\n    return str.slice(1);\n  }\n  return str;\n}\n\nexport async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {\n  if (!args.length) {\n    throw new MessageError(reporter.lang('missingWhyDependency'));\n  }\n  if (args.length > 1) {\n    throw new MessageError(reporter.lang('tooManyArguments', 1));\n  }\n\n  const query = await cleanQuery(config, args[0]);\n\n  reporter.step(1, 4, reporter.lang('whyStart', args[0]), emoji.get('thinking_face'));\n\n  // init\n  reporter.step(2, 4, reporter.lang('whyInitGraph'), emoji.get('truck'));\n  const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter);\n  const install = new Install(flags, config, reporter, lockfile);\n  const {requests: depRequests, patterns, workspaceLayout} = await install.fetchRequestFromCwd();\n  await install.resolver.init(depRequests, {\n    isFlat: install.flags.flat,\n    isFrozen: install.flags.frozenLockfile,\n    workspaceLayout,","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/why.js#L112-L148","documentation":"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.","triggerScenarios":"Running bare 'yarn why' with no arguments, so args.length is 0.","commonSituations":"User forgot the package name; script/alias invoked 'yarn why' without arguments.","solutions":["Pass a dependency name: 'yarn why <package>'.","You may pass a scoped name '@scope/pkg' or a path-style query."],"exampleFix":"# before\n$ yarn why\n# after\n$ yarn why lodash","handlingStrategy":"validation","validationCode":"if (!Array.isArray(args) || args.length === 0) {\n  throw new Error(\"'yarn why' requires exactly one dependency query argument.\");\n}","typeGuard":"function hasWhyQuery(args: string[]): boolean {\n  return Array.isArray(args) && args.length === 1;\n}","tryCatchPattern":null,"preventionTips":["Wrap 'yarn why' in a script that always supplies a query.","Validate arg count before invoking in automation."],"tags":["cli-args","validation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}