{"id":"5349ed6a0dd967ea","repo":"jestjs/jest","slug":"both-key-and-watchall-were-specified-but-c","errorCode":null,"errorMessage":"Both --${key} and --watchAll were specified, but cannot be used together. Try the --watch option which reruns only tests related to changed files.","messagePattern":"Both --(.+?) and --watchAll were specified, but cannot be used together\\. Try the --watch option which reruns only tests related to changed files\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-cli/src/args.ts","lineNumber":29,"sourceCode":"\nexport function check(argv: Config.Argv): true {\n  if (\n    argv.runInBand &&\n    Object.prototype.hasOwnProperty.call(argv, 'maxWorkers')\n  ) {\n    throw new Error(\n      'Both --runInBand and --maxWorkers were specified, only one is allowed.',\n    );\n  }\n\n  for (const key of [\n    'onlyChanged',\n    'lastCommit',\n    'changedFilesWithAncestor',\n    'changedSince',\n  ]) {\n    if (argv[key] && argv.watchAll) {\n      throw new Error(\n        `Both --${key} and --watchAll were specified, but cannot be used ` +\n          'together. Try the --watch option which reruns only tests ' +\n          'related to changed files.',\n      );\n    }\n  }\n\n  if (argv.onlyFailures && argv.watchAll) {\n    throw new Error(\n      'Both --onlyFailures and --watchAll were specified, only one is allowed.',\n    );\n  }\n\n  if (argv.findRelatedTests && argv._.length === 0) {\n    throw new Error(\n      'The --findRelatedTests option requires file paths to be specified.\\n' +\n        'Example usage: jest --findRelatedTests ./src/source.js ' +\n        './src/index.js.',","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-cli/src/args.ts#L11-L47","documentation":"The `check` function loops over the change-detection flags (`onlyChanged`, `lastCommit`, `changedFilesWithAncestor`, `changedSince`) and throws if any is combined with `--watchAll` (packages/jest-cli/src/args.ts:22). `--watchAll` reruns every test on any file change, which contradicts the 'only run tests for changed files' semantics. The message points users to `--watch`, which reruns only tests related to changed files.","triggerScenarios":"`jest --onlyChanged --watchAll`, `jest -o --watchAll`, `jest --changedSince=main --watchAll`, or `jest --lastCommit --watchAll`.","commonSituations":"Wanting watch mode plus change-scoping and reaching for the broader `--watchAll`; copy-pasting a watch script and adding a changed-files flag; IDE integrations that default to watchAll.","solutions":["Replace `--watchAll` with `--watch` — `--watch` already implies change-detection scoping and composes with onlyChanged/changedSince.","If you truly want to rerun ALL tests on every change, drop the changed-files flag instead."],"exampleFix":"# before\njest --onlyChanged --watchAll\n\n# after\njest --onlyChanged --watch","handlingStrategy":"validation","validationCode":"const CHANGED_FLAGS = ['onlyChanged','lastCommit','changedFilesWithAncestor','changedSince'] as const;\nfunction validateWatchFlags(argv: any): void {\n  if (argv.watchAll && CHANGED_FLAGS.some(k => argv[k])) {\n    throw new Error('Use --watch (not --watchAll) with change-detection flags');\n  }\n}","typeGuard":"const usesChangedFiles = (a: any) =>\n  Boolean(a.onlyChanged || a.lastCommit || a.changedFilesWithAncestor || a.changedSince);","tryCatchPattern":null,"preventionTips":["Prefer `--watch` whenever you also pass a changed-files flag.","Centralize watch-mode scripts to avoid ad-hoc flag combos.","Teammates: `-o`/`--onlyChanged` pairs with `--watch`, not `--watchAll`."],"tags":["jest-cli","cli-args","watch","onlychanged"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}