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

  1. Supply the option's value: e.g. `mocha --reporter spec`, `mocha --timeout 2000`.
  2. Inspect the full command line for an option sitting at the end or directly before another flag.
  3. In scripts, guard variable expansion: `${REPORTER:-spec}` or fail fast if the variable is unset.
  4. 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

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


AI-assisted analysis of mochajs/mocha@6bcbee4fd9 (2026-09-01). Data as JSON: /api/errors/74313c3feb45778e. Report an issue: GitHub.