jestjs/jest · error · TypeError

Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.

Error message

Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.

What it means

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.

Source

Thrown at packages/jest-core/src/runJest.ts:232

      const matches = await getTestPaths(
        globalConfig,
        context.config,
        searchSource,
        outputStream,
        changedFilesPromise && (await changedFilesPromise),
        jestHooks,
        filter,
      );
      allTests = [...allTests, ...matches.tests];

      return {context, matches};
    }),
  );
  performance.mark('jest/getTestPaths:end');

  if (globalConfig.shard) {
    if (typeof sequencer.shard !== 'function') {
      throw new TypeError(
        `Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.`,
      );
    }
    allTests = await sequencer.shard(allTests, globalConfig.shard);
  }

  allTests = await sequencer.sort(allTests);

  if (globalConfig.onlyFailures) {
    if (failedTestsCache) {
      allTests = failedTestsCache.filterTests(allTests);
    } else {
      allTests = await sequencer.allFailedTests(allTests);
    }
  }

  if (globalConfig.listTests) {
    const testsPaths = [...new Set(allTests.map(test => test.path))];

View on GitHub (pinned to f49721c78e)

Solutions

  1. Add a `shard(tests, options)` method to your custom sequencer — typically `return tests.filter((_, i) => i % options.shardCount === options.shardIndex - 1)`.
  2. If you do not need custom ordering, remove the `testSequencer` config so the default sequencer (which has `shard`) is used.
  3. Extend `@jest/test-sequencer` default class instead of implementing the interface from scratch so you inherit `shard`.
  4. Confirm the sequencer module path resolves and exports a class, not an instance.

Example fix

// before
class MySequencer {
  sort(tests) { return tests; }
}
module.exports = MySequencer;

// after
const Sequencer = require('@jest/test-sequencer').default;
class MySequencer extends Sequencer {
  sort(tests) { return tests; }
  // shard is inherited from the base class
}
module.exports = MySequencer;
Defensive patterns

Strategy: validation

Validate before calling

const Sequencer = require(globalConfig.testSequencer).default;
if (typeof Sequencer.prototype.shard !== 'function') {
  throw new Error(`sequencer ${Sequencer.name} lacks shard(); cannot use --shard`);
}

Type guard

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';

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/71cc7082e6749ce9.json. Report an issue: GitHub.