vitest-dev/vitest · error · Error

`bench.from()` could not find a result file at "${resolved}"

Error message

`bench.from()` could not find a result file at "${resolved}". Run the source benchmark first to create it.

What it means

Thrown by `resolveFromSource` (benchmark.ts:244) when `bench.from(name, source)` is given a string path but `rpc().readBenchmarkResult(resolved)` returns null, i.e. no result file exists at that resolved path. `bench.from()` loads a previously written baseline to compare against; the source benchmark must have run first (with `writeResult`) to create the file.

Source

Thrown at packages/vitest/src/runtime/benchmark.ts:244

}

export function createBench(
  test: Test,
  config: SerializedConfig,
  moduleRunner: TestModuleRunner,
): Bench {
  const pending = new Set<BenchRegistration<any>>()

  const resolveTemplate = (template: string) => substitutePath(template, config.benchmark.projectName)

  const resolveFromSource = async (source: string | BenchFromSource): Promise<BaselineData> => {
    if (typeof source === 'function') {
      return source()
    }
    const resolved = resolveTemplate(source)
    const data = await rpc().readBenchmarkResult(resolved)
    if (data == null) {
      throw new Error(`\`bench.from()\` could not find a result file at "${resolved}". Run the source benchmark first to create it.`)
    }
    return data
  }

  const taskFromBaseline = (
    name: string,
    data: BaselineData,
  ): TestBenchmarkTask => ({
    name,
    latency: data.latency,
    throughput: data.throughput,
    period: data.period,
    totalTime: data.totalTime,
    rank: 0,
    fromStore: true,
  })

  const createCompareStorage = <T extends string>(

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Run the source benchmark (the one with `writeResult`) first so the baseline file is created.
  2. Ensure the path passed to `bench.from()` matches the `writeResult` path of the source benchmark (including `${projectName}` substitution).
  3. Verify the file exists at the resolved path before running the comparison test.

Example fix

// before
bench.from('baseline', './results/sort.json')  // file missing
// source benchmark must write it first:
bench('sort', { writeResult: './results/sort.json' }, () => { /* ... */ })

// run the source, then the comparison
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'node:fs'
import { resolve } from 'node:path'
const resolved = resolve(source)
if (!existsSync(resolved)) throw new Error(`bench.from() baseline missing: ${resolved}; run the source benchmark first`)

Prevention

When it happens

Trigger: Calling `bench.from('baseline', './results/sort.json')` before any benchmark wrote `./results/sort.json`; the `writeResult` path of the source benchmark differs from the `bench.from()` path; the result file was deleted or never written because the source run failed.

Common situations: Running the comparison/baseline test without first running the source benchmark that writes the result; path template mismatch (e.g. `${projectName}` substitution differing between write and read); different working directories between writes and reads.

Related errors


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