{"id":"afe702a3be5f5b96","repo":"jestjs/jest","slug":"the-shard-option-requires-1-based-values-received","errorCode":null,"errorMessage":"The shard option requires 1-based values, received 0 or lower in the pair.","messagePattern":"The shard option requires 1-based values, received 0 or lower in the pair\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/parseShardPair.ts","lineNumber":27,"sourceCode":"  shardIndex: number;\n}\n\nexport const parseShardPair = (pair: string): ShardPair => {\n  const shardPair = pair\n    .split('/')\n    .filter(d => /^\\d+$/.test(d))\n    .map(d => Number.parseInt(d, 10));\n\n  const [shardIndex, shardCount] = shardPair;\n\n  if (shardPair.length !== 2) {\n    throw new Error(\n      'The shard option requires a string in the format of <n>/<m>.',\n    );\n  }\n\n  if (shardIndex === 0 || shardCount === 0) {\n    throw new Error(\n      'The shard option requires 1-based values, received 0 or lower in the pair.',\n    );\n  }\n\n  if (shardIndex > shardCount) {\n    throw new Error(\n      'The shard option <n>/<m> requires <n> to be lower or equal than <m>.',\n    );\n  }\n\n  return {\n    shardCount,\n    shardIndex,\n  };\n};\n","sourceCodeStart":9,"sourceCodeEnd":43,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/parseShardPair.ts#L9-L43","documentation":"After parseShardPair confirms two numeric segments exist, it checks that neither is zero. Shards are 1-based, so both shard index 0 and shard count 0 are invalid. The /^\\d+$/ pre-filter already excludes negatives, but \"0\" is a digit so it reaches this explicit guard.","triggerScenarios":"Passing `--shard \"0/4\"` (zero index), `--shard \"2/0\"` (zero count), `--shard \"0/0\"`, or a CI variable that defaults to 0.","commonSituations":"CI platforms that use 0-based indexing (some Docker/parallel setups) being fed into Jest's 1-based shard option; off-by-one in matrix arithmetic.","solutions":["Use 1-based values: the first shard is --shard 1/N and the last is --shard N/N","If your CI is 0-based, add 1 to the index before passing it: --shard \"$((CI_NODE_INDEX+1))/$CI_NODE_TOTAL\"","Ensure the shard count (second number) is at least 1"],"exampleFix":"// before (0-based CI index)\njest --shard \"$CI_NODE_INDEX/$CI_NODE_TOTAL\"\n// after\njest --shard \"$((CI_NODE_INDEX + 1))/$CI_NODE_TOTAL\"","handlingStrategy":"validation","validationCode":"function validateShardValues(s: string): void {\n  const [n, m] = s.split('/').map(Number);\n  if (!n || n < 1 || !m || m < 1) {\n    throw new Error('shard values must be >= 1');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document in CI config comments that Jest shards are 1-based","Assert shard index >= 1 in CI before invoking jest"],"tags":["cli","sharding","ci"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}