{"id":"71cc7082e6749ce9","repo":"jestjs/jest","slug":"shard-globalconfig-shard-shardindex-globalcon","errorCode":null,"errorMessage":"Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.","messagePattern":"Shard (.+?)/(.+?) requested, but test sequencer (.+?) in (.+?) has no shard method\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-core/src/runJest.ts","lineNumber":232,"sourceCode":"      const matches = await getTestPaths(\n        globalConfig,\n        context.config,\n        searchSource,\n        outputStream,\n        changedFilesPromise && (await changedFilesPromise),\n        jestHooks,\n        filter,\n      );\n      allTests = [...allTests, ...matches.tests];\n\n      return {context, matches};\n    }),\n  );\n  performance.mark('jest/getTestPaths:end');\n\n  if (globalConfig.shard) {\n    if (typeof sequencer.shard !== 'function') {\n      throw new TypeError(\n        `Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.`,\n      );\n    }\n    allTests = await sequencer.shard(allTests, globalConfig.shard);\n  }\n\n  allTests = await sequencer.sort(allTests);\n\n  if (globalConfig.onlyFailures) {\n    if (failedTestsCache) {\n      allTests = failedTestsCache.filterTests(allTests);\n    } else {\n      allTests = await sequencer.allFailedTests(allTests);\n    }\n  }\n\n  if (globalConfig.listTests) {\n    const testsPaths = [...new Set(allTests.map(test => test.path))];","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-core/src/runJest.ts#L214-L250","documentation":"Jest throws this TypeError when you pass `--shard` (or `globalConfig.shard`) but the configured `testSequencer` class does not implement a `shard` method. Sharding requires the sequencer to decide which tests belong to which shard, so Jest refuses to silently run everything and instead fails loudly at runJest.ts:232.","triggerScenarios":"Invoking Jest with `--shard=1/4` while `testSequencer` points to a custom sequencer that extends the default but does not override `shard`, or points to a third-party sequencer written before sharding support existed.","commonSituations":"Adopting sharding in CI on a repo that already has a custom testSequencer; upgrading Jest to a version that added sharding without updating the custom sequencer; copy-pasting an old sequencer from another project.","solutions":["Add a `shard(tests, options)` method to your custom sequencer — typically `return tests.filter((_, i) => i % options.shardCount === options.shardIndex - 1)`.","If you do not need custom ordering, remove the `testSequencer` config so the default sequencer (which has `shard`) is used.","Extend `@jest/test-sequencer` default class instead of implementing the interface from scratch so you inherit `shard`.","Confirm the sequencer module path resolves and exports a class, not an instance."],"exampleFix":"// before\nclass MySequencer {\n  sort(tests) { return tests; }\n}\nmodule.exports = MySequencer;\n\n// after\nconst Sequencer = require('@jest/test-sequencer').default;\nclass MySequencer extends Sequencer {\n  sort(tests) { return tests; }\n  // shard is inherited from the base class\n}\nmodule.exports = MySequencer;","handlingStrategy":"validation","validationCode":"const Sequencer = require(globalConfig.testSequencer).default;\nif (typeof Sequencer.prototype.shard !== 'function') {\n  throw new Error(`sequencer ${Sequencer.name} lacks shard(); cannot use --shard`);\n}","typeGuard":"const supportsShard = (S: new () => unknown): S is new () => { shard(tests: unknown[], o: {shardIndex: number; shardCount: number}): Promise<unknown[]> } => typeof (S.prototype as any).shard === 'function';","tryCatchPattern":null,"preventionTips":["Extend `@jest/test-sequencer` default class to inherit shard().","Add a CI preflight that checks shard support when --shard is enabled.","Keep the sequencer dependency version in sync with Jest."],"tags":["jest-core","sharding","test-sequencer","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}