{"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":"validation","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/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-cli/src/args.ts#L1-L35","documentation":"jest-cli's argument validator (packages/jest-cli/src/args.ts:12, the `check` function) rejects combining `--runInBand` (run serially in the main process) with `--maxWorkers` (explicit worker pool size), because they are mutually exclusive ways to control parallelism. `--runInBand` is effectively `--maxWorkers=1` constrained to the current process.","triggerScenarios":"Running `jest --runInBand --maxWorkers=4`, or a package.json script / CI config that concatenates both flags (often via env-variable expansion like `--maxWorkers=$MW` while a base script already adds `--runInBand`).","commonSituations":"Inheriting a script that uses runInBand for debugging and then appending maxWorkers for CI throughput; wrapper tools (Nx, turbo) that merge flag sets.","solutions":["Pick one: use `--maxWorkers=1` if you want serial execution with control, or `--runInBand` if you want serial execution in the main process (also needed for some debugging features).","Audit your package.json scripts and CI YAML for both flags and remove the redundant one.","If flags come from env vars, make them mutually exclusive in your script logic (e.g. only set maxWorkers when runInBand is not set)."],"exampleFix":"// before (package.json)\n\"scripts\": { \"test\": \"jest --runInBand --maxWorkers=2\" }\n\n// after\n\"scripts\": { \"test:serial\": \"jest --runInBand\", \"test:ci\": \"jest --maxWorkers=2\" }","handlingStrategy":"validation","validationCode":"// Validate argv before passing to jest-cli.\nfunction assertNoFlagConflict(argv: { runInBand?: boolean; maxWorkers?: number | string }): void {\n  if (argv.runInBand && argv.maxWorkers !== undefined) {\n    throw new Error('Pass either --runInBand or --maxWorkers, not both');\n  }\n}","typeGuard":"const hasOwn = (o: object, k: PropertyKey) => Object.prototype.hasOwnProperty.call(o, k);\nconst flagsConflict = (a: any) => Boolean(a.runInBand) && hasOwn(a, 'maxWorkers');","tryCatchPattern":null,"preventionTips":["Keep runInBand and maxWorkers in separate npm scripts.","When merging flags programmatically, drop one before invoking Jest.","Document which script is for debugging vs CI throughput."],"tags":["jest-cli","cli-args","workers","runinband"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}