vitest-dev/vitest · error · Error
task "${name}" was not defined
Error message
task "${name}" was not defined What it means
Thrown by the storage `get(name)` returned from `bench.compare(...)` (benchmark.ts:274) when you request a result by name that was not one of the registrations passed to `bench.compare()`. After a compare run, Vitest builds a result map keyed by registration name; looking up an undefined name means the task was never registered in that compare group.
Source
Thrown at packages/vitest/src/runtime/benchmark.ts:274
period: data.period,
totalTime: data.totalTime,
rank: 0,
fromStore: true,
})
const createCompareStorage = <T extends string>(
results: Map<string, BenchResult>,
fromResults?: Map<string, BaselineData>,
): BenchStorage<T> => {
return {
get(name: T) {
const stored = fromResults?.get(name)
if (stored) {
return stored as BenchResult
}
const result = results.get(name)
if (!result) {
throw new Error(`task "${name}" was not defined`)
}
return result
},
}
}
interface TaskMeta { perProject?: true }
const serializeBenchmark = (
results: BenchResult[],
name: string,
taskMeta?: Map<string, TaskMeta>,
fromTasks?: TestBenchmarkTask[],
): TestBenchmark => {
const tasks: TestBenchmarkTask[] = results.map(result => ({
name: result.name,
latency: result.latency,
throughput: result.throughput,View on GitHub (pinned to d568f8ce37)
Solutions
- Only call `storage.get(name)` with names that were registered in the same `bench.compare(...)` call.
- Double-check the spelling/casing of the name against the registration.
- Register the missing benchmark in the compare group if it should be part of the comparison.
Example fix
// before
const store = await bench.compare(
bench('one', fn1),
bench('two', fn2),
)
store.get('three') // throws
// after
store.get('one') Defensive patterns
Strategy: validation
Validate before calling
const validNames = new Set(registrations.map(r => r.name))
if (!validNames.has(requestedName)) throw new Error(`"${requestedName}" was not registered in bench.compare()`) Type guard
const isRegisteredName = (names: readonly string[], n: string): n is (typeof names)[number] => (names as readonly string[]).includes(n)
Prevention
- Capture registration names in a `const` tuple and look up only those literals.
- Avoid constructing names dynamically for storage lookups.
- Keep name strings identical between `bench(...)` and `storage.get(...)`.
When it happens
Trigger: Calling `storage.get('three')` when `bench.compare(oneReg, twoReg)` only registered `one` and `two`; a typo in the name; passing a different name string than the one used at registration.
Common situations: Refactoring benchmark names and forgetting to update lookups; copy-paste errors in the storage access; referencing a baseline name that wasn't included in the compare call.
Related errors
- `bench.compare()` requires at least 2 benchmarks, received $
- `bench.compare()` expects every argument to be the return va
- benchmark provider did not return a result for "${name}"
- `bench.from()` requires a name (string or named function) as
- `bench.from()` expects a string path or a function returning
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/e78d4340863a7804.json.
Report an issue: GitHub.