jestjs/jest · error · ModuleNotFoundError

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

Error message

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

What it means

`normalizeReporters` (packages/jest-config/src/normalize.ts:404) resolves each custom reporter path via the module resolver; if `Resolver.findNodeModule` returns null (and the name is not one of the built-ins 'default','agent','github-actions','summary'), it throws a `Resolver.ModuleNotFoundError`. The built-in names skip resolution.

Source

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

        ? // 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 f49721c78e)

Solutions

  1. Install the reporter package: `npm install --save-dev <reporter>`.
  2. Verify the path/name resolves from `rootDir` (use `require.resolve('<reporter>')` in a scratch script to test).
  3. If you only want a built-in reporter, use one of the recognized names: 'default', 'summary', 'github-actions'.

Example fix

// before
module.exports = { reporters: ['jest-junit'] }; // not installed

// after
// npm install --save-dev jest-junit
module.exports = { reporters: ['default', 'jest-junit'] };
Defensive patterns

Strategy: try-catch

Validate before calling

import {Resolver} from 'jest-resolve';
const BUILTIN = new Set(['default','agent','github-actions','summary']);
function assertReporterResolvable(name: string, rootDir: string): void {
  if (BUILTIN.has(name)) return;
  if (!Resolver.findNodeModule(name, { basedir: rootDir })) {
    throw new Error(`Reporter '${name}' not resolvable from ${rootDir}`);
  }
}

Type guard

const isBuiltinReporter = (n: string) =>
  ['default','agent','github-actions','summary'].includes(n);

Try / catch

try {
  require.resolve(reporterPath, { paths: [rootDir] });
} catch {
  throw new Error(`Custom reporter '${reporterPath}' missing; npm i -D ${reporterPath}`);
}

Prevention

When it happens

Trigger: `reporters: ['jest-dot-reporter']` where the package is not installed; a path like `<rootDir>/reporters/myReporter.js` that does not exist; typo in the reporter module name.

Common situations: Adding a custom reporter to config without installing it; reporter moved/renamed; CI environment missing a devDependency due to `--production` install or pruned lockfile.

Related errors


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