{"record":{"id":"55b35cc5593edc3e","repo":"jestjs/jest","slug":"could-not-resolve-a-module-for-a-custom-reporter","errorCode":null,"errorMessage":"Could not resolve a module for a custom reporter.\n  Module name: ${reporterPath}","messagePattern":"Could not resolve a module for a custom reporter\\.\n  Module name: (.+?)","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/normalize.ts","lineNumber":438,"sourceCode":"        ? // if reporter config is a string, we wrap it in an array\n          // and pass an empty object for options argument, to normalize\n          // the shape.\n          [reporterConfig, {}]\n        : reporterConfig;\n\n    const reporterPath = replaceRootDirInPath(\n      rootDir,\n      normalizedReporterConfig[0],\n    );\n\n    if (\n      !['agent', 'default', 'github-actions', 'summary'].includes(reporterPath)\n    ) {\n      const reporter = Resolver.findNodeModule(reporterPath, {\n        basedir: rootDir,\n      });\n      if (!reporter) {\n        throw new Resolver.ModuleNotFoundError(\n          'Could not resolve a module for a custom reporter.\\n' +\n            `  Module name: ${reporterPath}`,\n        );\n      }\n      normalizedReporterConfig[0] = reporter;\n    }\n    return normalizedReporterConfig;\n  });\n};\n\nconst buildTestPathPatterns = (argv: Config.Argv): TestPathPatterns => {\n  const patterns = [];\n\n  if (argv._) {\n    patterns.push(...argv._.map(x => x.toString()));\n  }\n  if (argv.testPathPatterns) {\n    patterns.push(...argv.testPathPatterns);","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/normalize.ts#L420-L456","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nmodule.exports = { reporters: ['jest-junit'] }; // not installed\n// after\nnpm install --save-dev jest-junit\n// or local:\nmodule.exports = { reporters: ['<rootDir>/reporters/myReporter.js'] };","handlingStrategy":"validation","validationCode":"import { Resolver } from 'jest-resolve';\nconst BUILTINS = ['default','agent','github-actions','summary'];\nfunction ensureReportersResolve(rootDir: string, reporters: Array<string | [string, object]>) {\n  for (const r of reporters) {\n    const name = typeof r === 'string' ? r : r[0];\n    if (BUILTINS.includes(name)) continue;\n    const resolved = Resolver.findNodeModule(name, { basedir: rootDir });\n    if (!resolved) throw new Error(`Reporter '${name}' not resolvable from ${rootDir}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["jest-config","reporter","module-resolution","dependency"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}