yarnpkg/yarn · error · MessageError
execMissingCommand
Error message
execMissingCommand
What it means
`yarn exec` shells out to a binary in the project's resolved PATH. At `exec.js:19` it requires at least one argument (the command); `args.length < 1` throws `execMissingCommand` ('Missing command name.') before constructing the env or spawning.
Source
Thrown at src/cli/commands/exec.js:19
// @flow
import type Config from '../../config.js';
import {MessageError} from '../../errors.js';
import type {Reporter} from '../../reporters/index.js';
import * as child from '../../util/child.js';
import {makeEnv} from '../../util/execute-lifecycle-script.js';
export function setFlags(commander: Object) {}
export function hasWrapper(commander: Object, args: Array<string>): boolean {
return true;
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
const env = await makeEnv(`exec`, config.cwd, config);
if (args.length < 1) {
throw new MessageError(reporter.lang('execMissingCommand'));
}
const [execName, ...rest] = args;
await child.spawn(execName, rest, {stdio: 'inherit', env});
}
View on GitHub (pinned to c2dda503f3)
Solutions
- Provide a command: `yarn exec eslint .`.
- If you meant to list scripts, use `yarn run` without arguments instead.
- In scripts, default/require the variable: `yarn exec "${CMD:?CMD required}"`.
Example fix
// before $ yarn exec // after $ yarn exec eslint src
Defensive patterns
Strategy: validation
Validate before calling
function requireExecCommand(args: string[]): string[] {
if (!Array.isArray(args) || args.length < 1) {
throw new Error('yarn exec requires a command name');
}
return args;
} Type guard
function hasExecCommand(args: unknown): args is [string, ...string[]] {
return Array.isArray(args) && typeof args[0] === 'string' && args[0].length > 0;
} Prevention
- In npm scripts, gate `yarn exec "$CMD"` with `${CMD:?CMD required}`.
- Prefer `yarn run <script>` for known tasks to avoid empty-command pitfalls.
When it happens
Trigger: Invoking `yarn exec` with no command token, e.g. `yarn exec` alone, or `yarn exec '$CMD'` where `$CMD` expands to empty.
Common situations: An npm script that calls `yarn exec` with a variable that is unset in CI, or running the command interactively by mistake.
Related errors
- missingAddDependencies
- invalidPackageName
- tooManyArguments
- tooFewArguments
- Name should not start with "/", got "${str}"
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/62478fbd587b72f3.
Report an issue: GitHub.