{"record":{"id":"c1b20d4f18f579ee","repo":"jestjs/jest","slug":"the-shard-option-requires-a-string-in-the-format-o","errorCode":null,"errorMessage":"The shard option requires a string in the format of <n>/<m>.","messagePattern":"The shard option requires a string in the format of <n>/<m>\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/parseShardPair.ts","lineNumber":21,"sourceCode":" *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nexport interface ShardPair {\n  shardCount: number;\n  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,","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/parseShardPair.ts#L3-L39","documentation":"Thrown by parseShardPair when the --shard CLI argument cannot be split into exactly two integer parts separated by '/'. The function splits on '/', filters parts matching /^\\d+$/, and requires exactly two surviving elements. Any value missing the slash, having non-numeric segments, or extra slashes produces this error.","triggerScenarios":"Passing jest --shard without arguments, with a single integer like '2', with a reversed/garbled pair like '2-of-4', with a missing half like '/4', or with text like 'two/four' (filtered out by the digit regex). Also triggered by passing empty string.","commonSituations":"CI matrix scripts that template the shard value incorrectly (e.g. $INDEX without $COUNT), shell quoting bugs that drop the slash, or copy-pasting shard syntax from older docs that used a different separator.","solutions":["Provide the shard as two 1-based integers separated by '/', e.g. --shard 1/4","If templating in CI, ensure both variables are substituted, e.g. --shard \"${CI_NODE_INDEX}/${CI_NODE_TOTAL}\"","Validate the value is a string containing exactly one '/' with digits on both sides before invoking Jest"],"exampleFix":"// before\njest --shard 2\n\n// after\njest --shard 2/4","handlingStrategy":"validation","validationCode":"function isValidShardPair(pair: string): boolean {\n  const parts = pair.split('/');\n  if (parts.length !== 2) return false;\n  return /^\\d+$/.test(parts[0]) && /^\\d+$/.test(parts[1]);\n}\n\nif (!isValidShardPair(process.env.SHARD)) {\n  throw new Error(`Invalid shard pair: ${process.env.SHARD}`);\n}","typeGuard":"function isShardPairString(value: unknown): value is string {\n  if (typeof value !== 'string') return false;\n  const parts = value.split('/');\n  return parts.length === 2 && /^\\d+$/.test(parts[0]) && /^\\d+$/.test(parts[1]);\n}","tryCatchPattern":null,"preventionTips":["Validate the shard string with a regex (/^\\d+\\/\\d+$/) before passing it to Jest","In CI, assert both index and total variables are non-empty before composing the shard value","Centralize shard computation in one CI script so the format is correct in all jobs"],"tags":["cli","sharding","ci","argument-validation"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}