{"id":"9df9f1c7aff6b389","repo":"vitest-dev/vitest","slug":"failed-to-load-benchmark-provider-from-provider","errorCode":null,"errorMessage":"Failed to load benchmark provider from \"${provider}\".","messagePattern":"Failed to load benchmark provider from \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark.ts","lineNumber":108,"sourceCode":" *\n * @experimental\n */\nexport interface BenchmarkProvider {\n  run: (group: BenchmarkGroup) => Promise<BenchResult[]>\n}\n\nlet cachedProvider: Promise<BenchmarkProvider> | undefined\n\nasync function loadProviderModule(\n  provider: string,\n  moduleRunner: TestModuleRunner,\n): Promise<BenchmarkProvider> {\n  let mod: Record<string, any>\n  try {\n    mod = await moduleRunner.import(provider)\n  }\n  catch (error) {\n    throw new Error(\n      `Failed to load benchmark provider from \"${provider}\".`,\n      { cause: error },\n    )\n  }\n  if (mod.default == null) {\n    throw new Error(\n      `Benchmark provider loaded from \"${provider}\" did not have a default export.`,\n    )\n  }\n  return mod.default\n}\n\n/**\n * Resolves the benchmark provider for the current worker, importing a custom\n * provider module on first use. The result is cached for the lifetime of the\n * worker so a custom provider is imported at most once.\n */\nexport function resolveBenchmarkProvider(","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/benchmark.ts#L90-L126","documentation":"Thrown by `loadProviderModule` (benchmark.ts:108) when `moduleRunner.import(provider)` rejects while importing a custom benchmark provider module. The underlying error is attached as `cause`. A custom benchmark provider is enabled via `test.benchmark.provider`; if that module path cannot be resolved or throws on import, Vitest wraps the failure with this message.","triggerScenarios":"Setting `benchmark.provider: './my-provider.ts'` where the file is missing, has a syntax error, throws during top-level execution, or imports an unavailable package; typo in the module path.","commonSituations":"Typo in the provider path; missing peer dependency the provider imports; ESM/CJS resolution issue; pointing at a non-existent package name.","solutions":["Inspect `error.cause` for the true import failure.","Verify the provider path exists and is resolvable from the project root.","Install any dependencies the provider imports; ensure no syntax errors.","If pointing at a package, confirm it is installed and exports a valid entry."],"exampleFix":"// before\ndefineConfig({ test: { benchmark: { provider: './benhc-provider.ts' /* typo */ } } })\n// after\ndefineConfig({ test: { benchmark: { provider: './bench-provider.ts' } } })","handlingStrategy":"try-catch","validationCode":"import { pathExists } from 'fs-extra'\nif (!await pathExists(providerPath)) throw new Error(`Benchmark provider not found: ${providerPath}`)","typeGuard":null,"tryCatchPattern":"try {\n  await import(providerPath)\n} catch (e) {\n  throw new Error(`Benchmark provider ${providerPath} failed to load`, { cause: e })\n}","preventionTips":["Verify the provider path before referencing it in config.","Keep provider dependencies installed.","Smoke-test the provider module in isolation."],"tags":["benchmark","custom-provider","import","config"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}