{"record":{"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":"exception","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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-cli/src/args.ts#L11-L47","documentation":"check() loops over the git/change-detection flags (onlyChanged, lastCommit, changedFilesWithAncestor, changedSince) and rejects each when combined with --watchAll (args.ts:22-35). --watchAll reruns ALL tests on any file change, which would defeat the purpose of the change-scoped flags; Jest suggests --watch instead, which reruns only tests related to changed files.","triggerScenarios":"Running jest --onlyChanged --watchAll; jest -o --watchAll; jest --changedSince=main --watchAll; jest --lastCommit --watchAll; jest --changedFilesWithAncestor --watchAll.","commonSituations":"Combining a workflow that filters by git changes with a watch-all habit; migrating from --watch to --watchAll without dropping the change flag; an editor plugin passing --watchAll over a script that already sets --onlyChanged.","solutions":["Replace --watchAll with --watch (keeps the change-scoped behavior and re-runs only affected tests).","Or drop the change-detection flag and keep --watchAll to rerun everything on save.","Review your IDE/watch plugin settings so they don't inject --watchAll on top of an --onlyChanged script."],"exampleFix":"// before\njest --onlyChanged --watchAll\n// after\njest --onlyChanged --watch","handlingStrategy":"validation","validationCode":"const CHANGE_FLAGS = ['onlyChanged','lastCommit','changedFilesWithAncestor','changedSince'] as const;\nfunction validateWatch(argv: Record<string, any>): void {\n  if (!argv.watchAll) return;\n  for (const k of CHANGE_FLAGS) {\n    if (argv[k]) throw new Error(`--${k} cannot be combined with --watchAll; use --watch`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer --watch (change-scoped) over --watchAll when using onlyChanged-style flags.","Document in your repo's test script which watch mode is canonical.","Audit editor/IDE plugins that may inject --watchAll."],"tags":["jest-cli","cli-args","conflicting-flags","watch","onlychanged"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}