vitest-dev/vitest · error · Error
Browser provider is not defined for the project "${child.pro
Error message
Browser provider is not defined for the project "${child.project.name}". This is a bug in Vitest. Please, open a new issue with a reproduction. What it means
While generating the virtual `vitest/browser` context module, Vitest reads `child.config.browser.provider.name` to embed the provider name in the bundled client code. If that field is undefined, it indicates provider resolution never completed for this project — the message explicitly asks for a bug report because every browser project should have a resolved provider name by this point.
Source
Thrown at packages/browser/src/node/plugins/pluginContext.ts:50
}
}
async function generateContextFile(
this: Rollup.PluginContext,
globalServer: ParentBrowserProject,
) {
const commands = Object.keys(globalServer.commands)
// The provider instance is initialized lazily when a page opens, so reading
// `child.provider` here races and can be `undefined` before the first page is
// opened. The provider name is uniform across a project's instances and is
// already resolved on the config, so read it from there for this shared
// (cached) context module. The instance is still used below for the
// preview-only user-event import.
const child = [...globalServer.children][0]
const provider = child.provider
const providerName = child.config.browser.provider?.name
if (!providerName) {
throw new Error(
`Browser provider is not defined for the project "${child.project.name}". This is a bug in Vitest. Please, open a new issue with a reproduction.`,
)
}
const commandsCode = commands
.filter(command => !command.startsWith('__vitest'))
.map((command) => {
return ` ["${command}"]: (...args) => __vitest_browser_runner__.commands.triggerCommand("${command}", args),`
})
.join('\n')
const userEventNonProviderImport = await getUserEventImport(
provider,
this.resolve.bind(this),
)
const distContextPath = slash(`/@fs/${resolve(__dirname, 'context.js')}`)
return `View on GitHub (pinned to d568f8ce37)
Solutions
- Install the browser provider package: `pnpm add -D @vitest/browser-playwright` (or `webdriverio`).
- Set `test.browser.provider` explicitly in the config (`'playwright'`, `'webdriverio'`, or `'preview'`).
- Verify `@vitest/browser` and the provider package match the installed `vitest` version.
- If config looks correct, follow the message and open a Vitest issue with a minimal reproduction.
Example fix
// before
export default defineConfig({
test: { browser: { enabled: true, name: 'chromium' } },
})
// after
export default defineConfig({
test: {
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
},
},
}) Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs'
import { resolve } from 'pathe'
function assertProviderConfigured(config: { browser?: { provider?: { name?: string } | string } }): void {
const name = typeof config.browser?.provider === 'string'
? config.browser.provider
: config.browser?.provider?.name
if (!name) {
throw new Error('test.browser.provider must be set (e.g. "playwright") before importing vitest/browser')
}
} Type guard
const hasProviderName = (c: { browser?: { provider?: { name?: string } | string } }): boolean => {
const p = c.browser?.provider
return typeof p === 'string' ? !!p : !!p?.name
} Prevention
- Always set `test.browser.provider` when `test.browser.enabled` is true.
- Install the matching provider package (@vitest/browser-playwright / -webdriverio).
- Keep vitest, @vitest/browser, and provider packages version-aligned.
When it happens
Trigger: Loading `vitest/browser` (e.g. importing it in a test or via the orchestrator) for a project whose `browser.provider.name` is falsy — provider resolution failed silently, the provider package isn't installed, or config explicitly left provider undefined while enabling browser mode.
Common situations: Missing `@vitest/browser` or a provider package (`@vitest/browser-playwright`, `@vitest/browser-webdriverio`); custom provider that doesn't expose `name`; mismatched Vitest/`@vitest/browser` versions where the config shape changed; corruption during config merge.
Related errors
- vitest/browser can be imported only inside the Browser Mode.
- No codec found for type ${type}
- Unrecognized comparator ${comparator}
- `resolveOptions` has to be used in a test file
- Tester HTML file "${testerHtmlPath}" doesn't exist.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/64e7976b17ddbade.json.
Report an issue: GitHub.