{"id":"77816376d9815727","repo":"vitest-dev/vitest","slug":"the-prefix-tag-is-not-defined-in-the-confi","errorCode":null,"errorMessage":"The ${prefix} \"${tag}\" is not defined in the configuration. Available tags are:\n${availableTags.map(t => `- ${t.name}${t.description ? `: ${t.description}` : ''}`).join('\\n')}","messagePattern":"The (.+?) \"(.+?)\" is not defined in the configuration\\. Available tags are:\n(.+?)(.+?)` : ''\\}`\\)\\.join\\('\\\\n'\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/runner/utils/tags.ts","lineNumber":41,"sourceCode":"\nexport function validateTags(config: SerializedConfig, tags: string[]): void {\n  if (!config.strictTags) {\n    return\n  }\n\n  const availableTags = new Set(config.tags.map(tag => tag.name))\n  for (const tag of tags) {\n    if (!availableTags.has(tag)) {\n      throw createNoTagsError(config.tags, tag)\n    }\n  }\n}\n\nexport function createNoTagsError(availableTags: TestTagDefinition[], tag: string, prefix = 'tag'): never {\n  if (!availableTags.length) {\n    throw new Error(`The Vitest config does't define any \"tags\", cannot apply \"${tag}\" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`)\n  }\n  throw new Error(`The ${prefix} \"${tag}\" is not defined in the configuration. Available tags are:\\n${availableTags\n    .map(t => `- ${t.name}${t.description ? `: ${t.description}` : ''}`)\n    .join('\\n')}`)\n}\n\nexport function createTagsFilter(tagsExpr: string[], availableTags: TestTagDefinition[]): (testTags: string[]) => boolean {\n  const matchers = tagsExpr.map(expr => parseTagsExpression(expr, availableTags))\n  return (testTags: string[]) => {\n    return matchers.every(matcher => matcher(testTags))\n  }\n}\n\ntype TagMatcher = (tags: string[]) => boolean\n\nfunction parseTagsExpression(expr: string, availableTags: TestTagDefinition[]): TagMatcher {\n  const tokens = tokenize(expr)\n  const stream = new TokenStream(tokens, expr)\n  const ast = parseOrExpression(stream, availableTags)\n  if (stream.peek().type !== 'EOF') {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/runner/utils/tags.ts#L23-L59","documentation":"Thrown by createNoTagsError when a test references a tag (via the @tag annotation) or a tag-filter expression references a tag/wildcard pattern that is not declared in the `tags` array of the Vitest config. The error lists every defined tag name and description so the developer can see exactly what is allowed. It only fires for test annotations when `config.strictTags` is true, but tag-filter resolution always validates against the defined tags.","triggerScenarios":"Called from validateTags (line 32, prefix='tag') when strictTags is enabled and a test decorator like `it('x', () => {}, { tags: ['slow'] })` names a tag absent from config.tags. Also called from resolveTagPattern (lines 273/279, prefix='tag pattern') when a --tag filter like `--tag 'smoke*'` or `--tag unit` has no match among defined tags.","commonSituations":"Enabling `strictTags: true` to catch typos, then having a test annotated with a tag that was never registered. Migrating test suites where tags were free-form strings before adopting the config-defined tag system. Running `vitest --tag integration` without having declared `integration` in config.tags. Typing a tag differently in the test vs the config (e.g. 'smoke-test' vs 'smoke').","solutions":["Add the missing tag name to the `tags` array in vitest.config: `tags: [{ name: 'integration', description: '...' }]`.","Fix the typo in the test annotation or filter expression so it matches an already-declared tag name exactly.","If the tag should be allowed freely without config registration, set `strictTags: false` (or omit it).","For wildcard filters, verify the pattern matches at least one declared tag name."],"exampleFix":"// before\nexport default defineConfig({\n  test: { strictTags: true, tags: [{ name: 'unit' }] }\n})\nit('x', () => {}, { tags: ['integration'] }) // throws\n\n// after\nexport default defineConfig({\n  test: { strictTags: true, tags: [{ name: 'unit' }, { name: 'integration' }] }\n})","handlingStrategy":"validation","validationCode":"// Before annotating tests, check the tag exists in config\nimport config from './vitest.config'\nconst declared = new Set((config.test?.tags ?? []).map(t => t.name))\nfunction assertTagKnown(tag: string) {\n  if (!declared.has(tag)) {\n    throw new Error(`Tag '${tag}' is not declared in config.test.tags`)\n  }\n}\nassertTagKnown('integration')","typeGuard":"import type { TestTagDefinition } from 'vitest'\nfunction isKnownTag(tag: string, defined: TestTagDefinition[]): tag is string {\n  return defined.some(t => t.name === tag)\n}","tryCatchPattern":null,"preventionTips":["Enable strictTags during CI to catch typos early.","Keep tags in a single shared constant imported by both config and tests.","Run `vitest --tag <name>` only with names that appear in config.tags."],"tags":["config","tags","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}