{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/utils/coverage.ts#L72-L104","documentation":"When test.coverage.provider is set to a custom value, Vitest loads the module at options.customProviderModule via the loader. If that import rejects (module not found, syntax error, runtime throw at load time), the original error is wrapped and re-thrown with { cause } pointing at the underlying failure and naming the configured module path.","triggerScenarios":"test.coverage.provider='custom' with coverage.customProviderModule pointing at a path/package that cannot be imported — wrong path, missing dependency, file does not exist, or the module throws during evaluation.","commonSituations":"Typo in customProviderModule path, relative path that does not resolve from the config location, the provider package is not installed, or the provider module throws on import (e.g. imports a missing peer dep).","solutions":["Verify the customProviderModule path resolves and the file/package exists.","Inspect error.cause (the wrapped error) for the real import failure (ENOENT, syntax error, missing dep).","Use an absolute path or a resolvable package name for customProviderModule.","Import the module manually (node -e \"import('./my-provider')\") to reproduce and fix the load error."],"exampleFix":"// before\ncoverage: { provider: 'custom', customProviderModule: './cov.js' }\n// file is actually ./src/cov.js\n\n// after\ncoverage: { provider: 'custom', customProviderModule: './src/cov.js' }","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nfunction assertProviderPath(p) {\n  if (!p) throw new Error('customProviderModule not set')\n  if (p.startsWith('.') && !existsSync(resolve(p))) throw new Error('provider file missing: ' + p)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await loader.import(customProviderModule)\n} catch (e) {\n  // e.cause has the real ENOENT/syntax error; surface it\n  throw new Error('cannot load provider: ' + e.cause?.message)\n}","preventionTips":["Use an absolute or package-name path for customProviderModule.","Import the provider manually first to confirm it loads.","Check error.cause for the underlying import failure."],"tags":["coverage","custom-provider","import","config"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}