vitest-dev/vitest · error · Error

The Vitest config does't define any "tags", cannot apply "${

Error message

The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags

What it means

`createNoTagsError` (tags.ts:37-44) is invoked when `strictTags` is enabled and a test/suite references a tag not defined in the config's `tags` array. When the config defines zero tags at all, this specific message is shown (the more detailed 'available tags' list variant is used when tags exist but the referenced one isn't among them). It directs the user to declare tags in config first.

Source

Thrown at packages/vitest/src/runtime/runner/utils/tags.ts:39

  return tagsFilterPredicate(testTags)
}

export function validateTags(config: SerializedConfig, tags: string[]): void {
  if (!config.strictTags) {
    return
  }

  const availableTags = new Set(config.tags.map(tag => tag.name))
  for (const tag of tags) {
    if (!availableTags.has(tag)) {
      throw createNoTagsError(config.tags, tag)
    }
  }
}

export function createNoTagsError(availableTags: TestTagDefinition[], tag: string, prefix = 'tag'): never {
  if (!availableTags.length) {
    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`)
  }
  throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:\n${availableTags
    .map(t => `- ${t.name}${t.description ? `: ${t.description}` : ''}`)
    .join('\n')}`)
}

export function createTagsFilter(tagsExpr: string[], availableTags: TestTagDefinition[]): (testTags: string[]) => boolean {
  const matchers = tagsExpr.map(expr => parseTagsExpression(expr, availableTags))
  return (testTags: string[]) => {
    return matchers.every(matcher => matcher(testTags))
  }
}

type TagMatcher = (tags: string[]) => boolean

function parseTagsExpression(expr: string, availableTags: TestTagDefinition[]): TagMatcher {
  const tokens = tokenize(expr)
  const stream = new TokenStream(tokens, expr)

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Define tags in your Vitest config: `test: { tags: [{ name: 'slow', description: '...' }] }`.
  2. Disable `strictTags` if you want undeclared tags to be allowed.
  3. Fix typos in the tag name to match a defined tag exactly.
  4. Refer to https://vitest.dev/guide/test-tags for the tags configuration schema.

Example fix

// before: vitest.config.ts
export default defineConfig({
  test: { strictTags: true /* no tags defined */ },
})
// test file
test('slow test', () => {}, { tags: ['slow'] }) // throws
// after: vitest.config.ts
export default defineConfig({
  test: {
    strictTags: true,
    tags: [{ name: 'slow', description: 'Long-running tests' }],
  },
})
Defensive patterns

Strategy: validation

Validate before calling

import type { TestTagDefinition } from 'vitest'
function tagIsDefined(config: { tags?: TestTagDefinition[] }, tag: string): boolean {
  return (config.tags ?? []).some(t => t.name === tag)
}
// before using a tag in a test:
if (!tagIsDefined(vitestConfig, 'slow')) {
  throw new Error('Define "slow" in config.test.tags or disable strictTags')
}

Type guard

function configHasTags(config: { tags?: TestTagDefinition[] }): config is { tags: TestTagDefinition[] } {
  return Array.isArray(config.tags) && config.tags.length > 0
}

Prevention

When it happens

Trigger: Setting `strictTags: true` in the Vitest config with an empty (or absent) `tags` array, then using `test('x', () => {}, { tags: ['slow'] })` or `describe('g', { tags: ['slow'] }, () => {})`. Also triggered by tag filter expressions referencing undefined tags.

Common situations: Enabling strictTags without first defining any tags in config; typos in tag names; copying tag usage from another project without importing its tag definitions; using tag-based filtering (`--tag`) before configuring tags.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/75b4f4a14d4692c8.json. Report an issue: GitHub.