yarnpkg/yarn · error · MessageError
missingAddDependencies
Error message
missingAddDependencies
What it means
Thrown by the `yarn add` entry point when no package arguments are supplied. The lang string is 'Missing list of packages to add to your project.' `add.js:308` checks `if (!args.length)` immediately after parsing argv, before any install logic runs, so it is a pure argument-validation failure.
Source
Thrown at src/cli/commands/add.js:308
export function hasWrapper(commander: Object): boolean {
return true;
}
export function setFlags(commander: Object) {
commander.description('Installs a package and any packages that it depends on.');
commander.usage('add [packages ...] [flags]');
commander.option('-W, --ignore-workspace-root-check', 'required to run yarn add inside a workspace root');
commander.option('-D, --dev', 'save package to your `devDependencies`');
commander.option('-P, --peer', 'save package to your `peerDependencies`');
commander.option('-O, --optional', 'save package to your `optionalDependencies`');
commander.option('-E, --exact', 'install exact version');
commander.option('-T, --tilde', 'install most recent release with the same minor version');
commander.option('-A, --audit', 'Run vulnerability audit on installed packages');
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
if (!args.length) {
throw new MessageError(reporter.lang('missingAddDependencies'));
}
const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter);
await wrapLifecycle(config, flags, async () => {
const install = new Add(args, flags, config, reporter, lockfile);
await install.init();
});
}
View on GitHub (pinned to c2dda503f3)
Solutions
- Supply at least one package specifier: `yarn add lodash@^4.17.0`.
- If scripting, default the variable: `yarn add "${PKG:?PKG is required}"`.
- When calling `run(...)` programmatically, assert `args.length >= 1` first.
Example fix
// before await run(config, reporter, flags, []); // throws // after await run(config, reporter, flags, ['lodash']);
Defensive patterns
Strategy: validation
Validate before calling
function requireAddArgs(args: string[]): string[] {
if (!Array.isArray(args) || args.length === 0) {
throw new Error('yarn add requires at least one package specifier');
}
return args;
}
// const safeArgs = requireAddArgs(args); await run(config, reporter, flags, safeArgs); Type guard
function hasAddArgs(args: unknown): args is string[] {
return Array.isArray(args) && args.length > 0;
} Prevention
- Wrap script variables with `${VAR:?msg}` so an unset variable aborts the shell.
- Unit-test wrappers that forward argv to confirm at least one positional arg.
When it happens
Trigger: Invoking `run(config, reporter, flags, args)` for the `add` command with an empty `args` array (e.g. `yarn add` with nothing after it).
Common situations: Typo such as `yarn add ` with a trailing space, a shell alias/script that forwards an empty variable (`yarn add $PKG` where `$PKG` is unset), or misuse of the programmatic API.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/a81481db4dfbef2e.
Report an issue: GitHub.