{"record":{"id":"d0eef8c3088e5748","repo":"vitest-dev/vitest","slug":"shard-count-must-be-a-smaller-than-count-of-te","errorCode":null,"errorMessage":"--shard <count> must be a smaller than count of test files. Resolved ${specs.length} test files for --shard=${ctx.config.shard.index}/${ctx.config.shard.count}.","messagePattern":"--shard <count> must be a smaller than count of test files\\. Resolved (.+?) test files for --shard=(.+?)/(.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/pool.ts","lineNumber":65,"sourceCode":"  const pool = new Pool({\n    distPath: ctx.distPath,\n    teardownTimeout: ctx.config.teardownTimeout,\n    state: ctx.state,\n  }, ctx.logger)\n\n  const options = resolveOptions(ctx)\n\n  const Sequencer = ctx.config.sequence.sequencer\n  const sequencer = new Sequencer(ctx)\n\n  let browserPool: ProcessPool | undefined\n\n  async function executeTests(method: 'run' | 'collect', specs: TestSpecification[], invalidates?: string[]): Promise<void> {\n    ctx.onCancel(() => pool.cancel())\n\n    if (ctx.config.shard) {\n      if (!ctx.config.passWithNoTests && ctx.config.shard.count > specs.length) {\n        throw new Error(\n          '--shard <count> must be a smaller than count of test files. '\n          + `Resolved ${specs.length} test files for --shard=${ctx.config.shard.index}/${ctx.config.shard.count}.`,\n        )\n      }\n      specs = await sequencer.shard(Array.from(specs))\n    }\n\n    const taskGroups: {\n      tasks: PoolTask[]\n      maxWorkers: number\n      // browser pool has a more complex logic, so we keep it separately for now\n      browserSpecs: TestSpecification[]\n    }[] = []\n    let workerId = 1\n\n    const sorted = await sequencer.sort(specs)\n    const { environments, tags } = await getSpecificationsOptions(specs)\n    const groups = groupSpecs(sorted, environments)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/pool.ts#L47-L83","documentation":"Sharding splits the resolved test files into N shards; shard.count must not exceed the number of matched files (unless passWithNoTests is set). Asking for more shards than files makes distribution impossible and Vitest throws with the resolved counts.","triggerScenarios":"--shard i/N (or config.test.shard = { index, count }) where shard.count > number of resolved specs, without passWithNoTests. The error embeds specs.length and the shard index/count.","commonSituations":"Over-sharding a small suite; sharding after a filter that reduces file count; CI matrix wider than the test count.","solutions":["Reduce --shard count to be <= the number of matched test files.","Pass --pass-with-no-tests (or set passWithNoTests: true) to allow empty shards.","Widen include globs / loosen filters so more files match the shard."],"exampleFix":"// before - 10 shards but only 4 files\nvitest run --shard 1/10\n\n// after\nvitest run --shard 1/4\n// or\nvitest run --shard 1/10 --pass-with-no-tests","handlingStrategy":"validation","validationCode":"function shardIsValid(shard, specsLength) {\n  return !shard || shard.count <= specsLength\n}\n// before run: if (!shardIsValid(config.shard, specs.length)) reduce shard.count or set passWithNoTests","typeGuard":null,"tryCatchPattern":"try {\n  await vitest.runFiles(specs)\n} catch (e) {\n  if (/shard/i.test(e.message) && /smaller than count of test files/i.test(e.message)) {\n    // reduce shard.count or pass --pass-with-no-tests, then retry\n  } else throw e\n}","preventionTips":["Size the shard matrix to the expected test file count, with headroom.","Set passWithNoTests when sharding may legitimately yield empty shards.","Resolve the spec list before computing shard dimensions."],"tags":["sharding","test-files","parallelism"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}