vitest-dev/vitest · error · TypeError
`bench()` does not accept options as the third argument. Pas
Error message
`bench()` does not accept options as the third argument. Pass options as the second argument instead: `bench(name, options, fn)`.
What it means
The `bench()` overloads are `bench(name, fn)` and `bench(name, options, fn)` — options come SECOND. `normalizeBenchArgs` (see `benchmark.ts:574`) treats a function second argument as `fn`; if a third argument is also present, it assumes you tried `bench(name, fn, options)` (options last) and throws this `TypeError` to redirect you to the correct order.
Source
Thrown at packages/vitest/src/runtime/benchmark.ts:574
}
return bench
}
function formatModuleId(moduleId: string, root: string): string {
if (!root || !isAbsolute(moduleId)) {
return moduleId
}
return relative(root, moduleId)
}
function normalizeBenchArgs(
a: BenchFn | BenchFnOptions,
b: BenchFn | BenchFnOptions | undefined,
): { fn: BenchFn; fnOpts: BenchOptions | undefined; writeResult: string | undefined; perProject: boolean } {
if (typeof a === 'function') {
if (b !== undefined) {
throw new TypeError('`bench()` does not accept options as the third argument. Pass options as the second argument instead: `bench(name, options, fn)`.')
}
return { fn: a, fnOpts: undefined, writeResult: undefined, perProject: false }
}
if (typeof b !== 'function') {
throw new TypeError('`bench()` expects a benchmark function. Call `bench(name, fn)` or `bench(name, options, fn)`.')
}
// Strip vitest-specific fields only when present so we don't allocate a new
// object — preserving referential identity matters: users inspect
// `registration.fnOpts` and the provider sees the same object the caller
// passed in.
if (a.writeResult === undefined && a.perProject === undefined) {
return { fn: b, fnOpts: a as BenchOptions, writeResult: undefined, perProject: false }
}
const { writeResult, perProject, ...fnOpts } = a
return {
fn: b,
fnOpts: Object.keys(fnOpts).length > 0 ? fnOpts as BenchOptions : undefined,
writeResult,View on GitHub (pinned to d568f8ce37)
Solutions
- Move options to the second slot: `bench('sort', { iterations: 100 }, () => x())`.
- If you don't need options, drop the third argument: `bench('sort', () => x())`.
Example fix
// before
bench('sort', () => sortArr(), { iterations: 100 })
// after
bench('sort', { iterations: 100 }, () => sortArr()) Defensive patterns
Strategy: validation
Validate before calling
// Enforce the correct argument order before calling bench.
function benchSafe(name: string, fnOrOpts: any, maybeOpts?: any) {
if (typeof fnOrOpts === 'function' && maybeOpts !== undefined) {
// user did bench(name, fn, opts) — reorder
return bench(name, maybeOpts, fnOrOpts)
}
return bench(name, fnOrOpts, maybeOpts)
} Try / catch
try {
bench(name, fn, opts)
} catch (e) {
if (e instanceof TypeError && /does not accept options as the third argument/.test(e.message)) {
bench(name, opts, fn) // correct order
} else throw e
} Prevention
- Remember the signature: bench(name, options?, fn) — options come BEFORE fn.
- Drop the options object entirely when you don't need it.
- Use an editor snippet that emits the correct argument order.
When it happens
Trigger: Calling `bench('sort', () => x(), { iterations: 100 })` — fn in slot 2, options in slot 3.
Common situations: Migrating from another benchmark API (tinybench, jest) where options come last; muscle memory from `it(name, fn, timeout)`.
Related errors
- `bench()` expects a benchmark function. Call `bench(name, fn
- `bench.from()` requires a name (string or named function) as
- `bench.from()` expects a string path or a function returning
- `bench.compare()` expects every argument to be the return va
- input with type=checkbox or type=radio cannot be used with .
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/bac948dff8b41bf2.json.
Report an issue: GitHub.