vitest-dev/vitest · error · Error
`bench.from()` could not find a result file at
Error message
`bench.from()` could not find a result file at "${resolved}". Run the source benchmark first to create it. What it means
`bench.from(name, source)` loads a previously stored benchmark baseline. When `source` is a string path, Vitest resolves it (with `${projectName}` substitution) and asks the server via `rpc().readBenchmarkResult(resolved)` for stored data. If nothing was written at that path, this error fires. Baselines are created by registering a benchmark with the `writeResult` option, which calls `writeBenchmarkResult` after a successful run.
Solutions
- Run the source benchmark first — register it with `bench('src', { writeResult: './results/src.json' }, fn)` and ensure it runs (`bench('src', fn).run()` or via `bench.compare`).
- Make the `writeResult` template in the source and the `source` argument to `bench.from()` use the identical path string and the same `${projectName}` substitution.
- If using a function source instead of a string, return the `BaselineData` directly to bypass file lookup.
- Verify the benchmark project's `projectName` config is identical between the writing run and the reading run.
Example fix
// before
bench('v1', { writeResult: './bench-v1.json' }, v1fn)
const baseline = bench.from('v1', './results/bench-v1.json') // wrong path
// after
bench('v1', { writeResult: './results/bench-v1.json' }, v1fn)
const baseline = bench.from('v1', './results/bench-v1.json') Defensive patterns
Strategy: validation
Validate before calling
const exists = await rpc().readBenchmarkResult(resolved); if (exists == null) throw new Error(`run the source benchmark with writeResult='${resolved}' first`) Type guard
null
Try / catch
try { reg = bench.from('base', './r.json') } catch (e) { if (/could not find a result file/.test(e.message)) { await writeSourceFirst(); reg = bench.from('base', './r.json') } else throw e } Prevention
- Keep the `writeResult` template and the `bench.from` source string in a shared constant.
- Run the writing benchmark in the same Vitest invocation (or a prior CI step) before the reader.
- Use the same `projectName` for both writer and reader to keep `${projectName}` substitution consistent.
When it happens
Trigger: Calling `bench.from('baseline', './results/my-bench.json')` before any benchmark has written results to that path. Also triggered by a mismatched `${projectName}` substitution — `source` uses `./${projectName}/baseline.json` but the writer used a different project name, so the resolved paths diverge.
Common situations: Running `bench.from` in CI before the source benchmark ran in the same or a prior step; the `writeResult` template in the source benchmark does not match the `from` source string; the results directory was cleaned; the project name changed between write and read.
Related errors
- `bench.from()` expects a string path or a function…
- `bench.from()` requires a name (string or named function)…
- `bench.compare()` expects every argument to be the return…
- `bench.compare()` requires at least 2 benchmarks, received
- `bench()` does not accept options as the third argument…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/56a67719177d166c.
Report an issue: GitHub.
Appendix: 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 1fa9837ec2)