vitest-dev/vitest · error · Error
Looks like you set "test.environment" to "browser". To enabl
Error message
Looks like you set "test.environment" to "browser". To enable Browser Mode, use "test.browser.enabled" instead.
What it means
Vitest removed the `environment: 'browser'` shorthand when Browser Mode became a first-class feature backed by its own server. The check at resolveConfig.ts:291 stops users from using the old string form and points them at `test.browser.enabled`, which is the only way to spin up the browser orchestrator, instances, and provider.
Source
Thrown at packages/vitest/src/node/config/resolveConfig.ts:292
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.`)
}
resolved.benchmark = {
...benchmarkConfigDefaults,
...resolved.benchmark,
}
if (resolved.benchmark.provider) {
resolved.benchmark.provider = resolvePath(
resolved.benchmark.provider,
resolved.root,
)
}
const inspector = resolved.inspect || resolved.inspectBrk
resolved.inspector = {
...resolved.inspector,
...parseInspector(inspector),View on GitHub (pinned to d568f8ce37)
Solutions
- Enable Browser Mode in config: `test: { browser: { enabled: true } }` and remove `environment: 'browser'`.
- If you only need a DOM, keep `environment: 'happy-dom'` or `environment: 'jsdom'` instead.
- If migrating, also add at least one `browser.instances` entry or rely on the default chromium instance.
Example fix
// before
export default defineConfig({ test: { environment: 'browser' } })
// after
export default defineConfig({ test: { browser: { enabled: true, instances: [{ browser: 'chromium' }] } } }) Defensive patterns
Strategy: type-guard
Validate before calling
function assertNoBrowserEnv(config: any) {
if (config?.test?.environment === 'browser') {
throw new Error('Use test.browser.enabled instead of test.environment: "browser".')
}
} Type guard
function usesBrowserMode(config: any): boolean {
return config?.test?.environment !== 'browser' && !!config?.test?.browser?.enabled
} Prevention
- Search the config for `environment: 'browser'` after upgrading Vitest.
- Bookmark the Browser Mode docs and migrate env strings to browser.enabled.
- For DOM-only tests prefer 'happy-dom' or 'jsdom'.
When it happens
Trigger: In config set `test: { environment: 'browser' }`, or pass `--environment browser` resolving to this config value. The equality check against the string 'browser' throws.
Common situations: Following an outdated tutorial or docs from a pre-Browser-Mode version; migrating from Jest's jsdom/browser env naming; muscle memory from the old happy-dom/node/browser environment list.
Related errors
- The `browser.provider` configuration was changed to accept a
- You've enabled headless mode for "preview" provider but it d
- vitest/browser can be imported only inside the Browser Mode.
- Not called in the browser
- Environment "${name}" is not a valid environment. Path "${pa
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/6256ff1826a1823a.json.
Report an issue: GitHub.