vitest-dev/vitest · error · Error

Looks like you set "test.environment" to "browser". To…

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'` shortcut. Browser Mode is now enabled through the dedicated `test.browser.enabled` flag (and `test.browser.instances`). Setting `test.environment` to the literal string `'browser'` is detected and rejected to prevent a silently misconfigured browser run, because the `browser` environment alone does not spin up the browser provider.

Solutions

  1. Remove `environment: 'browser'` and set `test.browser.enabled: true` instead.
  2. Define at least one entry in `test.browser.instances` (e.g. `[{ browser: 'chromium' }]`).
  3. Install the appropriate `@vitest/browser-*` provider package if you have not already.

Example fix

// before
test: { environment: 'browser' }
// after
test: { browser: { enabled: true, instances: [{ browser: 'chromium' }] } }
Defensive patterns

Strategy: validation

Validate before calling

if (config.test?.environment === 'browser') {
  throw new Error('Use test.browser.enabled instead of test.environment: "browser".')
}
// correct shape
config.test = { ...config.test, browser: { enabled: true, instances: [{ browser: 'chromium' }] } }

Type guard

function hasBrowserEnvShortcut(cfg: any): boolean {
  return cfg?.test?.environment === 'browser'
}

Prevention

When it happens

Trigger: Setting `environment: 'browser'` in a vitest config, or passing `--environment browser` on the CLI, or inheriting an older config that relied on the environment alias.

Common situations: Upgrading from an older Vitest where `environment: 'browser'` was the documented entry point; copy-pasting a stale blog post or example.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/6256ff1826a1823a. Report an issue: GitHub.

Appendix: source

Thrown at packages/vitest/src/node/config/resolveConfig.ts:320

      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 1fa9837ec2)