vitest-dev/vitest · error · Error

Cannot merge reports with --watch enabled

Error message

Cannot merge reports with --watch enabled

What it means

`--merge-reports` consumes previously written report files (from a sharded CI run, written via `--reporter` output files). Watch mode runs continuously and has no terminal point at which to merge. Vitest rejects `mergeReports && watch` because the operation is ill-defined.

Solutions

  1. Run the merge as a separate one-shot invocation without `--watch`.
  2. Remove `mergeReports` from the persistent config and pass it only on the merge CI step.
  3. Use distinct npm scripts for `test:watch` and `test:merge`.

Example fix

# before
vitest --merge-reports --watch
# after
vitest --merge-reports
Defensive patterns

Strategy: validation

Validate before calling

const mergeReports = process.argv.includes('--merge-reports')
const watch = process.argv.includes('--watch')
if (mergeReports && watch) {
  throw new Error('Cannot merge reports while watching; drop --watch for the merge step.')
}

Prevention

When it happens

Trigger: Running `vitest --merge-reports --watch`, or a config/CLI combo where `mergeReports: true` coincides with `watch: true`.

Common situations: A wrapper script that always adds `--watch` for local dev reused in a merge step; leftover `mergeReports` in config.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/2163f8646399c949. Report an issue: GitHub.

Appendix: source

Thrown at packages/vitest/src/node/config/resolveConfig.ts:377

    if (Number.isNaN(count) || count <= 0) {
      throw new Error('--shard <count> must be a positive number')
    }

    if (Number.isNaN(index) || index <= 0 || index > count) {
      throw new Error(
        '--shard <index> must be a positive number less then <count>',
      )
    }

    resolved.shard = { index, count }
  }

  if (resolved.standalone && !resolved.watch) {
    throw new Error(`Vitest standalone mode requires --watch`)
  }

  if (resolved.mergeReports && resolved.watch) {
    throw new Error(`Cannot merge reports with --watch enabled`)
  }

  if (resolved.maxWorkers) {
    resolved.maxWorkers = resolveInlineWorkerOption(resolved.maxWorkers)
  }

  // `browser.fileParallelism` was replaced by the top-level `fileParallelism`. Map
  // it (only when browser is enabled, since it was a browser-only option) so
  // existing configs keep working instead of being silently ignored.
  const browserOptions = options.browser as { enabled?: boolean; fileParallelism?: boolean } | undefined
  const browserFileParallelism = browserOptions?.enabled ? browserOptions.fileParallelism : undefined
  if (browserFileParallelism !== undefined) {
    logger.deprecate('`browser.fileParallelism` is deprecated. Use the top-level `fileParallelism` option instead.')
  }

  const fileParallelism = options.fileParallelism ?? browserFileParallelism ?? true

  if (!fileParallelism) {

View on GitHub (pinned to 1fa9837ec2)