{"id":"3d4f9814e546e7ef","repo":"vitest-dev/vitest","slug":"tag-name-tag-name-is-already-defined-in-test","errorCode":null,"errorMessage":"Tag name \"${tag.name}\" is already defined in \"test.tags\". Tag names must be unique.","messagePattern":"Tag name \"(.+?)\" is already defined in \"test\\.tags\"\\. Tag names must be unique\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/config/resolveConfig.ts","lineNumber":265,"sourceCode":"\n  if ('workspace' in resolved) {\n    throw new Error('The `test.workspace` option was removed in Vitest 4. Please, migrate to `test.projects` instead. See https://vitest.dev/guide/projects for examples.')\n  }\n\n  resolved.pool ??= 'forks'\n\n  resolved.project = toArray(resolved.project)\n  resolved.provide ??= {}\n\n  // shallow copy tags array to avoid mutating user config\n  resolved.tags = [...resolved.tags || []]\n  const definedTags = new Set<string>()\n  resolved.tags.forEach((tag) => {\n    if (!tag.name || typeof tag.name !== 'string') {\n      throw new Error(`Each tag defined in \"test.tags\" must have a \"name\" property, received: ${JSON.stringify(tag)}`)\n    }\n    if (definedTags.has(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is already defined in \"test.tags\". Tag names must be unique.`)\n    }\n    if (/\\s/.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot contain spaces.`)\n    }\n    if (/[!()*|&]/.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot contain \"!\", \"*\", \"&\", \"|\", \"(\", or \")\".`)\n    }\n    if (/^\\s*(?:and|or|not)\\s*$/i.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot be a logical operator like \"and\", \"or\", \"not\".`)\n    }\n    if (typeof tag.retry === 'object' && typeof tag.retry.condition === 'function') {\n      throw new TypeError(`Tag \"${tag.name}\": retry.condition function cannot be used inside a config file. Use a RegExp pattern instead, or define the function in your test file.`)\n    }\n    if (tag.priority != null && (typeof tag.priority !== 'number' || tag.priority < 0)) {\n      throw new TypeError(`Tag \"${tag.name}\": priority must be a non-negative number.`)\n    }\n    definedTags.add(tag.name)\n  })","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/config/resolveConfig.ts#L247-L283","documentation":"Thrown during tag validation when two entries in `test.tags` share the same `name`. Vitest tracks tag names in a Set as it iterates; encountering a duplicate means filtering by that name would be ambiguous, so it is rejected. Tag names must be unique across the whole config.","triggerScenarios":"Defining `test.tags: [{ name: 'unit' }, { name: 'unit' }]`, or merging multiple config presets that both declare a tag with the same name (deepMerge concatenates/overwrites, leaving duplicates).","commonSituations":"Combining shared tag presets; copy-paste; monorepo per-project configs merged at the root that each define the same tag.","solutions":["Deduplicate tags so each name appears once; merge metadata for the colliding tags into a single entry.","When merging presets, dedupe by name in a config-builder function before assigning to `test.tags`.","Namespace tag names if two distinct concepts collided (e.g. 'unit-core' vs 'unit-cli')."],"exampleFix":"// before\nexport default defineConfig({ test: { tags: [\n  { name: 'unit', retry: 1 },\n  { name: 'unit', priority: 2 },\n] } })\n// after\nexport default defineConfig({ test: { tags: [\n  { name: 'unit', retry: 1, priority: 2 },\n] } })","handlingStrategy":"validation","validationCode":"const seen = new Set<string>()\nfor (const t of tags) {\n  if (seen.has(t.name)) throw new Error(`duplicate tag: ${t.name}`)\n  seen.add(t.name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dedupe tags by name when merging presets.","Namespace names if distinct concepts collided.","Validate uniqueness in a config-builder test."],"tags":[],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}