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
- Install the reporter package: npm install --save-dev <reporter-name>.
- Use the correct path; for local files use '<rootDir>/path/to/reporter.js'.
- Verify the package name is spelled exactly (including @scope) and is in node_modules.
- 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
- Install reporter packages (jest-junit, jest-html-reporters, etc.) as devDependencies.
- Use <rootDir> tags for local reporter module paths.
- Confirm the reporter module exports a class compatible with Jest's reporter API.
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
- Cannot find module
- notify reporter requires optional peer dependency…
- Attempted to display seed but seed value is undefined
- Cannot merge config in form of callback
- haste.enableSymlinks is incompatible with watchman
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)