vitest-dev/vitest · error · Error

Failed to load benchmark provider from "${provider}".

Error message

Failed to load benchmark provider from "${provider}".

What it means

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.

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.
 */
export function resolveBenchmarkProvider(

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Inspect `error.cause` for the true import failure.
  2. Verify the provider path exists and is resolvable from the project root.
  3. Install any dependencies the provider imports; ensure no syntax errors.
  4. If pointing at a package, confirm it is installed and exports a valid entry.

Example fix

// before
defineConfig({ test: { benchmark: { provider: './benhc-provider.ts' /* typo */ } } })
// after
defineConfig({ test: { benchmark: { provider: './bench-provider.ts' } } })
Defensive patterns

Strategy: try-catch

Validate before calling

import { pathExists } from 'fs-extra'
if (!await pathExists(providerPath)) throw new Error(`Benchmark provider not found: ${providerPath}`)

Try / catch

try {
  await import(providerPath)
} catch (e) {
  throw new Error(`Benchmark provider ${providerPath} failed to load`, { cause: e })
}

Prevention

When it happens

Trigger: 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.

Common situations: Typo in the provider path; missing peer dependency the provider imports; ESM/CJS resolution issue; pointing at a non-existent package name.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/9df9f1c7aff6b389.json. Report an issue: GitHub.