vitest-dev/vitest · error · Error
Cannot create a benchmark project because the name
Error message
Cannot create a benchmark project because the name "${name}" is already in use. What it means
For each benchmark-enabled project, Vitest synthesizes a sibling benchmark project auto-named `${projectConfig.name} (bench)`, or just `bench` when the project has no name. Both names go into the shared `names` set; if the generated benchmark name already exists, resolution aborts to prevent two projects shadowing each other in reports.
Solutions
- Give every benchmark-enabled project a unique `name`.
- Avoid naming a non-benchmark project with a string ending in ` (bench)` that another project would generate.
- Disable `benchmark` on projects that should not spawn a benchmark variant.
Example fix
// before: two unnamed projects, both benchmark-enabled
projects: [
{ test: { benchmark: { include: ['bench/a.bench.ts'] } } },
{ test: { benchmark: { include: ['bench/b.bench.ts'] } } },
]
// after
projects: [
{ test: { name: 'a', benchmark: { include: ['bench/a.bench.ts'] } } },
{ test: { name: 'b', benchmark: { include: ['bench/b.bench.ts'] } } },
] Defensive patterns
Strategy: validation
Validate before calling
// Ensure benchmark-suffixed names won't collide.
function assertBenchmarkNamesUnique(projects: Array<{ name?: string; benchmark?: { enabled?: boolean } }>) {
const names = new Set(projects.map(p => p.name).filter(Boolean) as string[])
for (const p of projects) {
if (p.benchmark?.enabled === false) continue
const benchName = p.name ? `${p.name} (bench)` : 'bench'
if (names.has(benchName)) {
throw new Error(`Benchmark project name '${benchName}' would collide. Give benchmark-enabled projects unique names.`)
}
names.add(benchName)
}
} Prevention
- Name every benchmark-enabled project explicitly.
- Avoid the literal suffix ` (bench)` in hand-authored project names.
When it happens
Trigger: `names.has(name)` true inside `expandBenchmarksInEntries`, where `name` is computed at resolveProjects.ts:993. Triggers when two projects produce the same suffix (e.g. two unnamed projects both yield `bench`), or a real project is already named exactly `'<x> (bench)'`.
Common situations: Multiple unnamed benchmark-enabled projects in one config; a project literally named `bench` while another unnamed benchmark project exists.
Related errors
- Cannot define a nested project for a
- Project name " " from " " is not unique. The project is…
- Project name " " is not unique. All projects should have…
- Tag name " " is invalid. Tag names cannot contain spaces.
- Tag name " " is invalid. Tag names cannot contain "!", "*"…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/e5acc0bfb140fd6d.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/projects/resolveProjects.ts:996
*/
function expandBenchmarksInEntries(
entries: ResolvedProjectEntry[],
names: Set<string>,
benchmarkOnly: boolean,
): ResolvedProjectEntry[] {
let lastGroupOrder = Math.max(0, ...entries.map(e => e.projectConfig.sequence.groupOrder))
const result = [...entries]
for (const entry of entries) {
const benchmark = entry.projectConfig.benchmark
if ((!benchmark.enabled && !benchmarkOnly) || entry.hidden) {
continue
}
const name = entry.projectConfig.name ? `${entry.projectConfig.name} (bench)` : 'bench'
if (names.has(name)) {
throw new Error(`Cannot create a benchmark project because the name "${name}" is already in use.`)
}
names.add(name)
const benchmarkConfig: ResolvedConfig = {
...entry.projectConfig,
name,
include: benchmark.include,
exclude: benchmark.exclude,
includeSource: benchmark.includeSource,
coverage: {
...entry.projectConfig.coverage,
enabled: false,
},
maxWorkers: 1,
maxConcurrency: 1,
testTimeout: entry.projectConfig.testTimeout < 60_000 ? 60_000 : entry.projectConfig.testTimeout,
hookTimeout: entry.projectConfig.hookTimeout < 120_000 ? 120_000 : entry.projectConfig.hookTimeout,
// `enabled` because the original entry might not be benchmark-enabled (whenView on GitHub (pinned to 1fa9837ec2)