vitest-dev/vitest · error · Error
Failed to load benchmark provider from
Error message
Failed to load benchmark provider from "${provider}". What it means
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.
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.
Example fix
// before: benchmark.provider = './benchProvder' (typo) // after: benchmark.provider = './benchProvider'
Defensive patterns
Strategy: try-catch
Validate before calling
try { await import.meta.resolve!(providerPath) } catch { throw new Error(`provider path '${providerPath}' does not resolve`) } Type guard
null
Try / catch
try { bench = createBench(test, config, runner) } catch (e) { if (e.cause) console.error('underlying import error:', e.cause); throw e } Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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).
Related errors
- benchmark provider did not return a result for
- Benchmark provider loaded from
- Cannot use the `bench` test-context fixture within a…
- All browser instances within a project must use the same…
- `bench.compare()` expects every argument to be the return…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/9df9f1c7aff6b389.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/runtime/benchmark.ts:108
*
* @experimental
*/
export interface BenchmarkProvider {
run: (group: BenchmarkGroup) => Promise<BenchResult[]>
}
let cachedProvider: Promise<BenchmarkProvider> | undefined
async function loadProviderModule(
provider: string,
moduleRunner: TestModuleRunner,
): Promise<BenchmarkProvider> {
let mod: Record<string, any>
try {
mod = await moduleRunner.import(provider)
}
catch (error) {
throw new Error(
`Failed to load benchmark provider from "${provider}".`,
{ cause: error },
)
}
if (mod.default == null) {
throw new Error(
`Benchmark provider loaded from "${provider}" did not have a default export.`,
)
}
return mod.default
}
/**
* Resolves the benchmark provider for the current worker, importing a custom
* provider module on first use. The result is cached for the lifetime of the
* worker so a custom provider is imported at most once.
*/
function resolveBenchmarkProvider(View on GitHub (pinned to 1fa9837ec2)