{"record":{"id":"75b4f4a14d4692c8","repo":"vitest-dev/vitest","slug":"the-vitest-config-does-t-define-any-tags-cannot","errorCode":null,"errorMessage":"The Vitest config does't define any \"tags\", cannot apply \"${tag}\" ${prefix} for this test. See: https://vitest.dev/guide/test-tags","messagePattern":"The Vitest config does't define any \"tags\", cannot apply \"(.+?)\" (.+?) for this test\\. See: https://vitest\\.dev/guide/test-tags","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/runner/utils/tags.ts","lineNumber":39,"sourceCode":"  return tagsFilterPredicate(testTags)\n}\n\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)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/runner/utils/tags.ts#L21-L57","documentation":"Thrown by createNoTagsError when a test (or suite) references a tag but the Vitest config defines zero tags via the `tags` option. Vitest's strict-tags feature (on by default via strictTags) requires every tag used in test files to be declared in the config first, so an empty `tags` array means no tag can be applied. The message is produced from two call sites: validateTags (collection-time, prefix='tag') and resolveTagPattern (CLI filter evaluation, prefix='tag pattern').","triggerScenarios":"A test/suite calls `test('x', { tags: ['smoke'] }, fn)` or `describe('x', () => {}, { tags: ['smoke'] })`, or the CLI `--tag smoke` is passed, while `defineConfig({ tags: [] })` or no `tags` key at all is set. Because strictTags defaults to true (serializeConfig.ts:157), the check always runs unless explicitly disabled.","commonSituations":"Developers add `{ tags: [...] }` to a test before declaring the tag in vitest.config; teams adopting the tags feature for the first time and forgetting the config half; copying a test from another project that used tags into a project whose config has none.","solutions":["Add a `tags` array to your vitest config defining every tag you use, e.g. `defineConfig({ tags: [{ name: 'smoke' }] })`.","If you intentionally want undeclared tags allowed, set `strictTags: false` in the config.","Remove the `tags` option from the offending test/suite if tagging was unintended.","Confirm the tag name in the test exactly matches a `name` in config.tags (case-sensitive)."],"exampleFix":"// before\ntest('auth', { tags: ['smoke'] }, () => {})\n// vitest.config.ts — no tags key\n\n// after (vitest.config.ts)\nexport default defineConfig({\n  tags: [{ name: 'smoke', description: 'critical-path checks' }],\n})","handlingStrategy":"validation","validationCode":"// Run before adding a tag to a test/suite\nimport { getTagsFromConfig } from './test-helpers' // returns the Set of declared tag names\nconst declared = getTagsFromConfig() // from defineConfig.tags\nconst tagsToAdd = ['smoke']\nconst unknown = tagsToAdd.filter(t => !declared.has(t))\nif (declared.size === 0 && tagsToAdd.length) {\n  throw new Error('No tags declared in vitest config; add the `tags` option first.')\n}","typeGuard":"function isTagDeclared(declared: ReadonlySet<string>, tag: string): boolean {\n  return declared.size > 0 && declared.has(tag)\n}","tryCatchPattern":null,"preventionTips":["Centralize the list of tag names as a const and reuse it in both defineConfig.tags and tests.","Enable strictTags (the default) in CI so undeclared tags fail fast.","Add an editor lint rule or pre-commit check that greps test files for `{ tags: [...] }` against the declared set."],"tags":["config","tags","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}