{"record":{"id":"c48cce2c2810e60b","repo":"vitest-dev/vitest","slug":"failed-to-load-custom-reporter-from-path","errorCode":null,"errorMessage":"Failed to load custom Reporter from ${path}","messagePattern":"Failed to load custom Reporter from (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/reporters/utils.ts","lineNumber":18,"sourceCode":"import type { ModuleRunner } from 'vite/module-runner'\nimport type { Vitest } from '../core'\nimport type { ResolvedConfig } from '../types/config'\nimport type { Reporter } from '../types/reporter'\nimport type { BlobReporter } from './blob'\nimport type { BuiltinReporters, DefaultReporter, DotReporter, GithubActionsReporter, HangingProcessReporter, JsonReporter, JUnitReporter, TapReporter } from './index'\nimport { ReportersMap } from './index'\n\nasync function loadCustomReporterModule<C extends Reporter>(\n  path: string,\n  runner: ModuleRunner,\n): Promise<new (options?: unknown) => C> {\n  let customReporterModule: { default: new () => C }\n  try {\n    customReporterModule = await runner.import(path)\n  }\n  catch (customReporterModuleError) {\n    throw new Error(`Failed to load custom Reporter from ${path}`, {\n      cause: customReporterModuleError as Error,\n    })\n  }\n\n  if (\n    customReporterModule.default === null\n    || customReporterModule.default === undefined\n  ) {\n    throw new Error(\n      `Custom reporter loaded from ${path} was not the default export`,\n    )\n  }\n\n  return customReporterModule.default\n}\n\nfunction createReporters(\n  reporterReferences: ResolvedConfig['reporters'],","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/reporters/utils.ts#L1-L36","documentation":"Vitest tried to dynamically import the custom reporter module at `path` and the import itself threw (module not found, syntax error, top-level throw, unsupported ESM/CJS). The original error is attached as `cause` so the real reason is preserved; this outer message only identifies which reporter path failed.","triggerScenarios":"`reporters: [['./wrong-path.js', {}]]` or any non-builtin reporter name that resolves to a module that errors on import; `loadCustomReporterModule` catches the import rejection and re-throws wrapped.","commonSituations":"Typo in the reporter path; missing dependency imported by the reporter; ESM/CJS interop failure; reporter file has a syntax error or throws at module top level.","solutions":["Inspect `error.cause` for the underlying module error (the real message).","Confirm the path resolves from the project root (Vitest resolves it via the module runner).","Reproduce the import standalone: `node -e \"import('./path').then(console.log).catch(console.error)\"`.","Fix the missing dependency / syntax error / interop issue inside the reporter module."],"exampleFix":"// inspecting the cause\ntry {\n  await startVitest('test', [], {}, { reporters: [['./my-reporter.js', {}]] })\n} catch (e) {\n  console.error(e.message)        // 'Failed to load custom Reporter from ./my-reporter.js'\n  console.error(e.cause)          // real error, e.g. Cannot find module 'pino'\n}","handlingStrategy":"try-catch","validationCode":"import { pathToFileURL } from 'node:url'\n// Pre-validate that the reporter module is importable from the project root.\nasync function assertReporterImportable(path: string) {\n  await import(pathToFileURL(resolve(process.cwd(), path)).href)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await startVitest('test', [], {}, { reporters: [[reporterPath, {}]] })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to load custom Reporter from ')) {\n    console.error('Underlying import error:', e.cause)\n    // fix the module, then retry\n  }\n  throw e\n}","preventionTips":["Resolve reporter paths from the project root; prefer absolute paths or package specifiers.","Test that `import(reporterPath)` works in isolation before wiring it into Vitest."],"tags":["reporter","config","module-loading"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}