vitest-dev/vitest · error · Error
Tag name " " is invalid. Tag names cannot be a logical…
Error message
Tag name "${tag.name}" is invalid. Tag names cannot be a logical operator like "and", "or", "not". What it means
Tag names cannot be the reserved logical operators `and`, `or`, `not` (case-insensitive, whitespace-trimmed). These words are keywords in Vitest's tag filter expression grammar, so using one as a tag name would collide with operator tokenisation.
Solutions
- Pick a non-reserved name: `logical-and`, `or-check`, `negated`.
- Namespace the tag: `myteam.and`.
- Validate names against the reserved list before exporting config.
Example fix
// before
export default defineConfig({ test: { tags: [{ name: 'or' }] } })
// after
export default defineConfig({ test: { tags: [{ name: 'or-gate' }] } }) Defensive patterns
Strategy: validation
Validate before calling
const RESERVED_WORDS = /^\s*(?:and|or|not)\s*$/i
function assertNotReservedWord(name: string): void {
if (RESERVED_WORDS.test(name)) {
throw new Error(`Tag name "${name}" is a reserved logical operator`)
}
}
rawTags.forEach(t => assertNotReservedWord(t.name)) Type guard
function isNonReservedName(name: string): boolean {
return typeof name === 'string' && !/^\s*(?:and|or|not)\s*$/i.test(name)
} Prevention
- Namespace tag names to avoid accidental collisions with operators.
- Maintain a denylist of reserved words when generating tags programmatically.
- Prefer domain-specific names over generic logical terms.
When it happens
Trigger: `{ name: 'and' }`, `{ name: 'OR' }`, `{ name: ' not ' }`, or any case variant matching `^\s*(?:and|or|not)\s*$`.
Common situations: Naming tags after domain concepts that happen to be these words; auto-generating tags from a taxonomy that includes operator-like terms.
Related errors
- Tag name " " is invalid. Tag names cannot contain "!", "*"…
- Each tag defined in "test.tags" must have a "name"…
- Tag name " " is already defined in "test.tags". Tag names…
- Tag name " " is invalid. Tag names cannot contain spaces.
- Tag " ": priority must be a non-negative number.
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/a92daa33e369dfac.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/config/resolveConfig.ts:302
// shallow copy tags array to avoid mutating user config
resolved.tags = [...resolved.tags || []]
const definedTags = new Set<string>()
resolved.tags.forEach((tag) => {
if (!tag.name || typeof tag.name !== 'string') {
throw new Error(`Each tag defined in "test.tags" must have a "name" property, received: ${JSON.stringify(tag)}`)
}
if (definedTags.has(tag.name)) {
throw new Error(`Tag name "${tag.name}" is already defined in "test.tags". Tag names must be unique.`)
}
if (/\s/.test(tag.name)) {
throw new Error(`Tag name "${tag.name}" is invalid. Tag names cannot contain spaces.`)
}
if (/[!()*|&]/.test(tag.name)) {
throw new Error(`Tag name "${tag.name}" is invalid. Tag names cannot contain "!", "*", "&", "|", "(", or ")".`)
}
if (/^\s*(?:and|or|not)\s*$/i.test(tag.name)) {
throw new Error(`Tag name "${tag.name}" is invalid. Tag names cannot be a logical operator like "and", "or", "not".`)
}
if (typeof tag.retry === 'object' && typeof tag.retry.condition === 'function') {
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.`)
}
if (tag.priority != null && (typeof tag.priority !== 'number' || tag.priority < 0)) {
throw new TypeError(`Tag "${tag.name}": priority must be a non-negative number.`)
}
definedTags.add(tag.name)
})
resolved.name = typeof options.name === 'string'
? options.name
: (options.name?.label || '')
resolved.color = typeof options.name !== 'string' ? options.name?.color : undefined
if (resolved.environment === 'browser') {
throw new Error(`Looks like you set "test.environment" to "browser". To enable Browser Mode, use "test.browser.enabled" instead.`)View on GitHub (pinned to 1fa9837ec2)