jestjs/jest · error · ModuleNotFoundError

Could not resolve a module for a custom reporter. Module…

Error message

Could not resolve a module for a custom reporter.
  Module name: ${reporterPath}

What it means

normalizeReporters (normalize.ts:409-447) resolves each custom reporter path through Resolver.findNodeModule. The four built-in names ('default','agent','github-actions','summary') are exempt; any other path that fails to resolve throws Resolver.ModuleNotFoundError with the reporterPath (lines 437-442). Jest needs the module to require it at runtime, so an unresolved reporter is fatal.

Solutions

  1. Install the reporter package: npm install --save-dev <reporter-name>.
  2. Use the correct path; for local files use '<rootDir>/path/to/reporter.js'.
  3. Verify the package name is spelled exactly (including @scope) and is in node_modules.
  4. Confirm the reporter module exports a class with the Jest reporter interface.

Example fix

// before
module.exports = { reporters: ['jest-junit'] }; // not installed
// after
npm install --save-dev jest-junit
// or local:
module.exports = { reporters: ['<rootDir>/reporters/myReporter.js'] };
Defensive patterns

Strategy: validation

Validate before calling

import { Resolver } from 'jest-resolve';
const BUILTINS = ['default','agent','github-actions','summary'];
function ensureReportersResolve(rootDir: string, reporters: Array<string | [string, object]>) {
  for (const r of reporters) {
    const name = typeof r === 'string' ? r : r[0];
    if (BUILTINS.includes(name)) continue;
    const resolved = Resolver.findNodeModule(name, { basedir: rootDir });
    if (!resolved) throw new Error(`Reporter '${name}' not resolvable from ${rootDir}`);
  }
}

Prevention

When it happens

Trigger: Setting reporters: ['jest-junit'] without installing it; reporters: ['./myReporter.js'] where the path is wrong; a typo in a reporter package name; a reporter path that needs <rootDir> substitution but is missing the tag.

Common situations: Adding a CI reporter (jest-junit, jest-html-reporters) but forgetting the dependency; moving reporter files during refactor; relative paths that don't account for cwd; scoped package typos.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/55b35cc5593edc3e. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-config/src/normalize.ts:438

        ? // if reporter config is a string, we wrap it in an array
          // and pass an empty object for options argument, to normalize
          // the shape.
          [reporterConfig, {}]
        : reporterConfig;

    const reporterPath = replaceRootDirInPath(
      rootDir,
      normalizedReporterConfig[0],
    );

    if (
      !['agent', 'default', 'github-actions', 'summary'].includes(reporterPath)
    ) {
      const reporter = Resolver.findNodeModule(reporterPath, {
        basedir: rootDir,
      });
      if (!reporter) {
        throw new Resolver.ModuleNotFoundError(
          'Could not resolve a module for a custom reporter.\n' +
            `  Module name: ${reporterPath}`,
        );
      }
      normalizedReporterConfig[0] = reporter;
    }
    return normalizedReporterConfig;
  });
};

const buildTestPathPatterns = (argv: Config.Argv): TestPathPatterns => {
  const patterns = [];

  if (argv._) {
    patterns.push(...argv._.map(x => x.toString()));
  }
  if (argv.testPathPatterns) {
    patterns.push(...argv.testPathPatterns);

View on GitHub (pinned to 8e6d128e4a)