{"id":"124aa4963bd33c17","repo":"vitest-dev/vitest","slug":"failed-to-load-custom-coverageprovidermodule-from","errorCode":null,"errorMessage":"Failed to load custom CoverageProviderModule from ${options.customProviderModule}","messagePattern":"Failed to load custom CoverageProviderModule from (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/utils/coverage.ts","lineNumber":90,"sourceCode":"        ? await loader.import(builtInModule)\n        : await import(/* @vite-ignore */ builtInModule)\n\n    if (!coverageModule) {\n      throw new Error(\n        `Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`,\n      )\n    }\n\n    return coverageModule\n  }\n\n  let customProviderModule\n\n  try {\n    customProviderModule = await loader.import(options.customProviderModule!)\n  }\n  catch (error) {\n    throw new Error(\n      `Failed to load custom CoverageProviderModule from ${options.customProviderModule}`,\n      { cause: error },\n    )\n  }\n\n  if (customProviderModule.default == null) {\n    throw new Error(\n      `Custom CoverageProviderModule loaded from ${options.customProviderModule} was not the default export`,\n    )\n  }\n\n  return customProviderModule.default\n}\n","sourceCodeStart":72,"sourceCodeEnd":104,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/utils/coverage.ts#L72-L104","documentation":"When provider is 'custom', Vitest dynamically imports options.customProviderModule via the runtime loader (coverage.ts:86-94). If that import rejects — module not found, syntax error, or the module throws on load — the original error is wrapped (with cause) into this message naming the configured module path.","triggerScenarios":"Configuring coverage.provider: 'custom' and coverage.customProviderModule: '<path>' where the path is wrong, the file is not valid JS/TS, or the module throws during top-level evaluation. The loader.import call rejects and is caught.","commonSituations":"Typo in the customProviderModule path; pointing at a file that no longer exists after a refactor; the custom provider module imports a dependency that is not installed; ESM/CJS interop error when loading the module.","solutions":["Verify the customProviderModule path resolves from the project root (try importing it from a script).","Inspect error.cause for the underlying module-load failure (missing dep, syntax error).","Install any dependency the custom provider module imports.","Ensure the module is valid for the current ESM/CJS context."],"exampleFix":"// before: path typo\nexport default defineConfig({\n  test: { coverage: { provider: 'custom', customProviderModule: './cov/provider.ts' } },\n})\n\n// after: correct existing path\nexport default defineConfig({\n  test: { coverage: { provider: 'custom', customProviderModule: './coverage/provider.ts' } },\n})","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nfunction assertCustomProviderPath(root: string, modulePath: string) {\n  const resolved = resolve(root, modulePath)\n  if (!existsSync(resolved)) {\n    throw new Error(`customProviderModule not found at '${resolved}'`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await resolveCoverageProviderModule(config.coverage, loader)\n} catch (e) {\n  const cause = (e as Error & { cause?: Error }).cause\n  console.error('Custom coverage provider failed to load:', cause?.message ?? e)\n  throw e\n}","preventionTips":["Point customProviderModule at a file that exists and imports cleanly.","Install every dependency the custom provider needs.","Test-import the module in isolation before wiring it into coverage config."],"tags":["coverage","custom-provider","module-load","config"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}