{"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":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/projects/resolveProjects.ts","lineNumber":800,"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":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/projects/resolveProjects.ts#L782-L818","documentation":"expandBenchmarksInEntries (resolveProjects.ts:797-801) injects a benchmark variant per benchmark-enabled entry, naming it `${parentName} (bench)` (or just 'bench' for unnamed projects). If that derived name is already in the `names` set (used by another project, browser instance, or an earlier benchmark variant), it throws.","triggerScenarios":"Two projects whose names both yield the same `${name} (bench)`; a project literally named 'bench' alongside an unnamed benchmark project; a previous benchmark variant occupying the name; --benchmark forcing every project to spawn a variant that collides.","commonSituations":"Running with --benchmark across projects where one is already named 'something (bench)'; a project named 'bench' colliding with the unnamed default; benchmark and browser expansion both targeting the same derived label.","solutions":["Rename the offending project so its `${name} (bench)` variant is unique.","Avoid naming a project 'bench' when running in benchmark mode.","Run benchmarks on a subset with --project to dodge the collision.","If two source projects collide only in benchmark mode, give them distinct names."],"exampleFix":"// before: a project named 'bench' plus --benchmark flag\n// 'bench' (bench) collides with the unnamed 'bench'\n\n// after: rename the source project\nclass Project { name = 'perf-core' } // variant becomes 'perf-core (bench)'","handlingStrategy":"validation","validationCode":"const benchNames = entries.filter(e => e.benchmark.enabled).map(e => e.name ? `${e.name} (bench)` : 'bench')\nif (new Set(benchNames).size !== benchNames.length) throw new Error('Benchmark variant name collision; rename source projects')","typeGuard":"function noBenchCollision(names: string[]): boolean {\n  const bench = names.map(n => n ? `${n} (bench)` : 'bench')\n  return new Set(bench).size === bench.length\n}","tryCatchPattern":null,"preventionTips":["Don't name a project 'bench' when using --benchmark.","Ensure source project names differ so their `${name} (bench)` variants differ.","Scope --benchmark to a subset with --project to avoid collisions."],"tags":["benchmark","naming","duplicate","configuration"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}