{"record":{"id":"e720dea4f22cbb3e","repo":"jestjs/jest","slug":"both-runinband-and-maxworkers-were-specified","errorCode":null,"errorMessage":"Both --runInBand and --maxWorkers were specified, only one is allowed.","messagePattern":"Both --runInBand and --maxWorkers were specified, only one is allowed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-cli/src/args.ts","lineNumber":17,"sourceCode":"/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport type {Options} from 'yargs';\nimport type {Config} from '@jest/types';\nimport {constants, isJSONString} from 'jest-config';\n\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  }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-cli/src/args.ts#L1-L35","documentation":"The check() validator in jest-cli/args.ts rejects combining --runInBand (run all tests in the parent process) with --maxWorkers (spawn N worker processes), because they are two contradictory ways of controlling parallelism (args.ts:13-20). Jest cannot honor both, so it fails fast with a clear message rather than silently picking one.","triggerScenarios":"Running jest -i --maxWorkers=2; setting both in a script (e.g. jest --runInBand --maxWorkers=50%); combining a CI flag preset (runInBand) with a locally-tuned maxWorkers in npm scripts; detectOpenHandles (which implies runInBand) combined with an explicit maxWorkers.","commonSituations":"Copy-pasting flags from two different Stack Overflow answers into one npm script; a base script sets --runInBand for debugging and an override adds --maxWorkers; CI config sets runInBand=true while the developer adds -w for speed.","solutions":["Remove one of the flags: use --runInBand for serial in-process debugging, OR --maxWorkers=N for parallelism.","If using --detectOpenHandles (which forces runInBand), drop the explicit --maxWorkers.","Audit your package.json scripts and CI matrix for inherited flags that collide."],"exampleFix":"// before\n\"scripts\": { \"test\": \"jest --runInBand --maxWorkers=2\" }\n// after\n\"scripts\": { \"test\": \"jest --runInBand\" }","handlingStrategy":"validation","validationCode":"function buildJestArgs(flags: { runInBand?: boolean; maxWorkers?: number | string }): string[] {\n  if (flags.runInBand && flags.maxWorkers !== undefined) {\n    throw new Error('Cannot use both runInBand and maxWorkers');\n  }\n  const args: string[] = [];\n  if (flags.runInBand) args.push('--runInBand');\n  else if (flags.maxWorkers !== undefined) args.push('--maxWorkers', String(flags.maxWorkers));\n  return args;\n}","typeGuard":"function isExclusiveConcurrency(flags: { runInBand?: boolean; maxWorkers?: number | string }): boolean {\n  return Boolean(flags.runInBand) !== Boolean(flags.maxWorkers !== undefined);\n}","tryCatchPattern":null,"preventionTips":["Centralize jest CLI construction in one helper so conflicting flags can't co-exist.","Review package.json scripts and CI matrices for inherited flags.","Remember that --detectOpenHandles implies --runInBand."],"tags":["jest-cli","cli-args","conflicting-flags","runinband","maxworkers"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}