jestjs/jest · error · Error
Both --onlyFailures and --watchAll were specified, only one…
Error message
Both --onlyFailures and --watchAll were specified, only one is allowed.
What it means
check() separately rejects --onlyFailures together with --watchAll (args.ts:37-41) because --onlyFailures relies on a static snapshot of the previous run's results, while --watchAll continuously reruns everything. The two modes operate on incompatible notions of which tests to select.
Solutions
- Drop --watchAll if you want to keep rerunning only previously-failed tests.
- Switch to plain --watch (reruns tests related to changed files) instead of --watchAll if you want live feedback.
- If you want both behaviors, run them as separate jest invocations.
Example fix
// before jest --onlyFailures --watchAll // after jest --onlyFailures
Defensive patterns
Strategy: validation
Validate before calling
function validateFlags(argv: { onlyFailures?: boolean; watchAll?: boolean }): void {
if (argv.onlyFailures && argv.watchAll) {
throw new Error('--onlyFailures and --watchAll are mutually exclusive');
}
} Prevention
- Keep --onlyFailures for one-shot reruns; use --watch (not --watchAll) for live feedback.
- Build a small CLI-flag wrapper that rejects known-incompatible pairs.
When it happens
Trigger: Running jest --onlyFailures --watchAll; jest -f --watchAll; combining a flaky-test rerun workflow with watch-all development.
Common situations: Adding --watchAll to a script that already uses --onlyFailures to chase down failing tests; aliasing watch to watchAll by mistake.
Related errors
- Both -- and --watchAll were specified, but cannot be used…
- Both --runInBand and --maxWorkers were specified, only one…
- The --maxWorkers (-w) option requires a number or string to…
- The --config option requires a JSON string literal, or a…
- The --findRelatedTests option requires file paths to be…
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/48155784e9d35da1.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-cli/src/args.ts:38
}
for (const key of [
'onlyChanged',
'lastCommit',
'changedFilesWithAncestor',
'changedSince',
]) {
if (argv[key] && argv.watchAll) {
throw new Error(
`Both --${key} and --watchAll were specified, but cannot be used ` +
'together. Try the --watch option which reruns only tests ' +
'related to changed files.',
);
}
}
if (argv.onlyFailures && argv.watchAll) {
throw new Error(
'Both --onlyFailures and --watchAll were specified, only one is allowed.',
);
}
if (argv.findRelatedTests && argv._.length === 0) {
throw new Error(
'The --findRelatedTests option requires file paths to be specified.\n' +
'Example usage: jest --findRelatedTests ./src/source.js ' +
'./src/index.js.',
);
}
if (
Object.prototype.hasOwnProperty.call(argv, 'maxWorkers') &&
argv.maxWorkers === undefined
) {
throw new Error(
'The --maxWorkers (-w) option requires a number or string to be specified.\n' +View on GitHub (pinned to 8e6d128e4a)