jestjs/jest · error · Error
Both --runInBand and --maxWorkers were specified, only one i
Error message
Both --runInBand and --maxWorkers were specified, only one is allowed.
What it means
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.
Source
Thrown at packages/jest-cli/src/args.ts:17
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {Options} from 'yargs';
import type {Config} from '@jest/types';
import {constants, isJSONString} from 'jest-config';
export function check(argv: Config.Argv): true {
if (
argv.runInBand &&
Object.prototype.hasOwnProperty.call(argv, 'maxWorkers')
) {
throw new Error(
'Both --runInBand and --maxWorkers were specified, only one is allowed.',
);
}
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.',
);
}
}View on GitHub (pinned to f49721c78e)
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).
Example fix
// before (package.json)
"scripts": { "test": "jest --runInBand --maxWorkers=2" }
// after
"scripts": { "test:serial": "jest --runInBand", "test:ci": "jest --maxWorkers=2" } Defensive patterns
Strategy: validation
Validate before calling
// Validate argv before passing to jest-cli.
function assertNoFlagConflict(argv: { runInBand?: boolean; maxWorkers?: number | string }): void {
if (argv.runInBand && argv.maxWorkers !== undefined) {
throw new Error('Pass either --runInBand or --maxWorkers, not both');
}
} Type guard
const hasOwn = (o: object, k: PropertyKey) => Object.prototype.hasOwnProperty.call(o, k); const flagsConflict = (a: any) => Boolean(a.runInBand) && hasOwn(a, 'maxWorkers');
Prevention
- 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.
When it happens
Trigger: 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`).
Common situations: Inheriting a script that uses runInBand for debugging and then appending maxWorkers for CI throughput; wrapper tools (Nx, turbo) that merge flag sets.
Related errors
- Both --${key} and --watchAll were specified, but cannot be u
- Both --onlyFailures and --watchAll were specified, only one
- The --findRelatedTests option requires file paths to be spec
- The --maxWorkers (-w) option requires a number or string to
- The --selectProjects option requires the name of at least on
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/e720dea4f22cbb3e.json.
Report an issue: GitHub.