{"record":{"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 */\nfunction resolveBenchmarkProvider(","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/benchmark.ts#L90-L126","documentation":"Vitest's benchmark system can load a custom `BenchmarkProvider` from a module path configured under `benchmark.provider`. This error wraps any failure thrown while importing that module via the module runner — the underlying import error is attached as `cause`. It means the module specifier itself could not be resolved, fetched, or evaluated.","triggerScenarios":"Setting `benchmark.provider: './my-provider'` where the path is wrong, the file has a syntax error, throws during top-level execution, or the module runner transport fails to fetch it. The try/catch at benchmark.ts:104-112 catches anything rejected by `moduleRunner.import(provider)` and re-throws with this message plus the original as `cause`.","commonSituations":"Typo in the provider path; provider module imports a dependency that is not installed; provider is ESM but loaded in a CJS context that throws; network/filesystem error in a custom transport; provider module throws at the top level (e.g. reads `process.env.SOMETHING` that is undefined and dereferences it).","solutions":["Inspect `error.cause` for the real import failure (resolution error, syntax error, runtime throw) and fix that root cause.","Confirm the path resolves from the project root — use a relative path or package name that the module runner can resolve.","Run the provider file standalone (`node --import tsx ./my-provider.ts`) to reproduce the top-level error outside Vitest.","If you did not intend to set a custom provider, remove `benchmark.provider` from config to fall back to the default tinybench-based provider."],"exampleFix":"// before: benchmark.provider = './benchProvder' (typo)\n// after: benchmark.provider = './benchProvider'","handlingStrategy":"try-catch","validationCode":"try { await import.meta.resolve!(providerPath) } catch { throw new Error(`provider path '${providerPath}' does not resolve`) }","typeGuard":"null","tryCatchPattern":"try { bench = createBench(test, config, runner) } catch (e) { if (e.cause) console.error('underlying import error:', e.cause); throw e }","preventionTips":["Resolve the provider path from the project root before configuring it.","Run the provider file standalone with `node --import tsx path.ts` to surface top-level throws.","Lock the provider module's dependencies so an install miss does not break imports in CI."],"tags":["benchmark","provider","configuration","module-import"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}