mochajs/mocha · error · Error
Not enough arguments following: ${name}
Error message
Not enough arguments following: ${name} What it means
Before handing arguments to yargs, Mocha validates that every option flagged as requiring a value actually has a following argument. `validateArgsBeforeParse` throws this error when an option like `--reporter` or `--timeout` appears at the end of the argument list or is followed by another dash-prefixed token (that isn't a negative number), meaning its value is missing.
Source
Thrown at lib/cli/parse-args.js:304
};
/**
* Disallows multiple arguments after a single option, such as `--grep abc def`.
*/
const validateArgsBeforeParse = (allArgs) => {
allArgs.forEach((arg, index) => {
if (!arg.startsWith("-") || arg === "--" || arg.includes("=")) {
return;
}
const name = canonicalOptionName(stripLeadingDashes(arg));
const next = allArgs[index + 1];
if (
requiresValue(name) &&
(next === undefined || (next.startsWith("-") && !isNumeric(next)))
) {
throw new Error(`Not enough arguments following: ${name}`);
}
});
};
const normalizeParsedValues = (values, positionals) => {
const normalized = Object.assign({ _: positionals }, values);
Object.keys(normalized).forEach((rawName) => {
if (rawName === "_") {
return;
}
const name = canonicalOptionName(rawName);
if (name !== rawName) {
normalized[name] = mergeValue(normalized[name], normalized[rawName]);
delete normalized[rawName];
}
});View on GitHub (pinned to 6bcbee4fd9)
Solutions
- Supply the option's value: e.g. `mocha --reporter spec`, `mocha --timeout 2000`.
- Inspect the full command line for an option sitting at the end or directly before another flag.
- In scripts, guard variable expansion: `${REPORTER:-spec}` or fail fast if the variable is unset.
- If a value itself legitimately starts with '-', use `--opt=-value` form or reorder arguments.
Example fix
// before $ mocha --reporter // Error: Not enough arguments following: --reporter // after $ mocha --reporter spec
Defensive patterns
Strategy: validation
Validate before calling
const VALUE_OPTS = ['--reporter','--timeout','--grep','--require','--ui','--spec','--config','--package','--node-option'];
function validate(argv) {
for (let i = 0; i < argv.length; i++) {
if (VALUE_OPTS.includes(argv[i])) {
const next = argv[i + 1];
if (next === undefined || (next.startsWith('-') && !/^-\d/.test(next))) {
throw new Error(`Missing value for ${argv[i]}`);
}
}
}
} Type guard
const hasValueAfter = (argv, i) => i + 1 < argv.length && !(argv[i + 1].startsWith('-') && !isNumeric(argv[i + 1])); Try / catch
try {
const { mochaArgs } = parseMochaArgs(rawArgs);
} catch (err) {
if (err.message.startsWith('Not enough arguments following:')) {
console.error(err.message + ' — supply a value for the option.');
process.exit(1);
}
throw err;
} Prevention
- Never end a command line with a value-taking option.
- Use `--opt=value` syntax to make value binding explicit.
- Guard interpolated script variables: `--reporter "${REPORTER:-spec}"`.
- Remember negative numbers (e.g. `--timeout -1`) are accepted values, other dash-tokens are not.
When it happens
Trigger: `mocha --reporter` (option last with no value); `mocha --timeout --grep foo` (option followed by another flag); `parseMochaArgs(['--require'])`; any option in `requiresValue(name)` whose next token is undefined or starts with '-' and is not numeric like `-1`.
Common situations: Typing `mocha --timeout` and forgetting `2000`; copy-pasted commands where a value was dropped; scripts interpolating empty variables (`mocha --reporter $EMPTY`); intentionally trying `--grep -2` works, but `--grep --diff` does not.
Related errors
- Not enough non-option arguments: got 0, need at least 1
- ERR_MOCHA_UNSUPPORTED
- ERR_MOCHA_MISSING_ARGUMENT
- Missing runner argument
- Missing runner argument
AI-assisted analysis of mochajs/mocha@6bcbee4fd9 (2026-09-01).
Data as JSON: /api/errors/74313c3feb45778e.
Report an issue: GitHub.