{"record":{"id":"e5acc0bfb140fd6d","repo":"vitest-dev/vitest","slug":"cannot-create-a-benchmark-project-because-the-name","errorCode":null,"errorMessage":"Cannot create a benchmark project because the name \"${name}\" is already in use.","messagePattern":"Cannot create a benchmark project because the name \"(.+?)\" is already in use\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/projects/resolveProjects.ts","lineNumber":996,"sourceCode":" */\nfunction expandBenchmarksInEntries(\n  entries: ResolvedProjectEntry[],\n  names: Set<string>,\n  benchmarkOnly: boolean,\n): ResolvedProjectEntry[] {\n  let lastGroupOrder = Math.max(0, ...entries.map(e => e.projectConfig.sequence.groupOrder))\n  const result = [...entries]\n\n  for (const entry of entries) {\n    const benchmark = entry.projectConfig.benchmark\n    if ((!benchmark.enabled && !benchmarkOnly) || entry.hidden) {\n      continue\n    }\n\n    const name = entry.projectConfig.name ? `${entry.projectConfig.name} (bench)` : 'bench'\n\n    if (names.has(name)) {\n      throw new Error(`Cannot create a benchmark project because the name \"${name}\" is already in use.`)\n    }\n    names.add(name)\n\n    const benchmarkConfig: ResolvedConfig = {\n      ...entry.projectConfig,\n      name,\n      include: benchmark.include,\n      exclude: benchmark.exclude,\n      includeSource: benchmark.includeSource,\n      coverage: {\n        ...entry.projectConfig.coverage,\n        enabled: false,\n      },\n      maxWorkers: 1,\n      maxConcurrency: 1,\n      testTimeout: entry.projectConfig.testTimeout < 60_000 ? 60_000 : entry.projectConfig.testTimeout,\n      hookTimeout: entry.projectConfig.hookTimeout < 120_000 ? 120_000 : entry.projectConfig.hookTimeout,\n      // `enabled` because the original entry might not be benchmark-enabled (when","sourceCodeStart":978,"sourceCodeEnd":1014,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/projects/resolveProjects.ts#L978-L1014","documentation":"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.","triggerScenarios":"`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)'`.","commonSituations":"Multiple unnamed benchmark-enabled projects in one config; a project literally named `bench` while another unnamed benchmark project exists.","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."],"exampleFix":"// before: two unnamed projects, both benchmark-enabled\nprojects: [\n  { test: { benchmark: { include: ['bench/a.bench.ts'] } } },\n  { test: { benchmark: { include: ['bench/b.bench.ts'] } } },\n]\n\n// after\nprojects: [\n  { test: { name: 'a', benchmark: { include: ['bench/a.bench.ts'] } } },\n  { test: { name: 'b', benchmark: { include: ['bench/b.bench.ts'] } } },\n]","handlingStrategy":"validation","validationCode":"// Ensure benchmark-suffixed names won't collide.\nfunction assertBenchmarkNamesUnique(projects: Array<{ name?: string; benchmark?: { enabled?: boolean } }>) {\n  const names = new Set(projects.map(p => p.name).filter(Boolean) as string[])\n  for (const p of projects) {\n    if (p.benchmark?.enabled === false) continue\n    const benchName = p.name ? `${p.name} (bench)` : 'bench'\n    if (names.has(benchName)) {\n      throw new Error(`Benchmark project name '${benchName}' would collide. Give benchmark-enabled projects unique names.`)\n    }\n    names.add(benchName)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name every benchmark-enabled project explicitly.","Avoid the literal suffix ` (bench)` in hand-authored project names."],"tags":["benchmark","config","naming"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}