{"record":{"id":"91e03115fe21154c","repo":"vitest-dev/vitest","slug":"you-cannot-use-shard-option-with-enabled-watch","errorCode":null,"errorMessage":"You cannot use --shard option with enabled watch","messagePattern":"You cannot use --shard option with enabled watch","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/config/resolveConfig.ts","lineNumber":352,"sourceCode":"  const inspector = resolved.inspect || resolved.inspectBrk\n\n  resolved.inspector = {\n    ...resolved.inspector,\n    ...parseInspector(inspector),\n    enabled: !!inspector,\n    waitForDebugger:\n      options.inspector?.waitForDebugger ?? !!resolved.inspectBrk,\n  }\n\n  if (viteConfig.base !== '/') {\n    resolved.base = viteConfig.base\n  }\n\n  resolved.clearScreen = resolved.clearScreen ?? viteConfig.clearScreen ?? true\n\n  if (options.shard) {\n    if (resolved.watch) {\n      throw new Error('You cannot use --shard option with enabled watch')\n    }\n\n    const [indexString, countString] = options.shard.split('/')\n    const index = Math.abs(Number.parseInt(indexString, 10))\n    const count = Math.abs(Number.parseInt(countString, 10))\n\n    if (Number.isNaN(count) || count <= 0) {\n      throw new Error('--shard <count> must be a positive number')\n    }\n\n    if (Number.isNaN(index) || index <= 0 || index > count) {\n      throw new Error(\n        '--shard <index> must be a positive number less then <count>',\n      )\n    }\n\n    resolved.shard = { index, count }\n  }","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/config/resolveConfig.ts#L334-L370","documentation":"Sharding splits a single test run into N parts (`--shard i/N`) for horizontal distribution across CI machines. Watch mode keeps Vitest alive and re-runs tests reactively; combining the two is contradictory because sharding assumes one finite run. Vitest refuses to start rather than silently ignoring one of the flags.","triggerScenarios":"Running `vitest --watch --shard 1/2`, or setting both `watch: true` and `shard: '1/2'` in config/CLI, or a script that always passes `--watch` together with a CI shard env var.","commonSituations":"A dev script that hard-codes `--watch` reused in CI; an env var like `SHARD_INDEX` leaking into a local watch session.","solutions":["Drop `--watch` (or set `watch: false`) when sharding in CI.","Drop `--shard` when running interactively in watch mode.","Gate the flags on an `CI` env var so watch is only added locally."],"exampleFix":"// before\nvitest --watch --shard 1/4\n// after (CI)\nvitest --shard 1/4\n// after (local)\nvitest --watch","handlingStrategy":"validation","validationCode":"const watch = !process.env.CI && process.argv.includes('--watch')\nconst shard = process.env.SENTRY_SHARD\nif (watch && shard) {\n  throw new Error('Refusing to start: --watch and --shard are mutually exclusive.')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Separate CI and local scripts; never pass `--watch` from a CI script.","Source `--shard` only inside CI-specific npm scripts."],"tags":["cli","shard","watch","ci"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}