{"id":"64e7976b17ddbade","repo":"vitest-dev/vitest","slug":"browser-provider-is-not-defined-for-the-project","errorCode":null,"errorMessage":"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.","messagePattern":"Browser provider is not defined for the project \"(.+?)\"\\. This is a bug in Vitest\\. Please, open a new issue with a reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/plugins/pluginContext.ts","lineNumber":50,"sourceCode":"  }\n}\n\nasync function generateContextFile(\n  this: Rollup.PluginContext,\n  globalServer: ParentBrowserProject,\n) {\n  const commands = Object.keys(globalServer.commands)\n  // The provider instance is initialized lazily when a page opens, so reading\n  // `child.provider` here races and can be `undefined` before the first page is\n  // opened. The provider name is uniform across a project's instances and is\n  // already resolved on the config, so read it from there for this shared\n  // (cached) context module. The instance is still used below for the\n  // preview-only user-event import.\n  const child = [...globalServer.children][0]\n  const provider = child.provider\n  const providerName = child.config.browser.provider?.name\n  if (!providerName) {\n    throw new Error(\n      `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.`,\n    )\n  }\n\n  const commandsCode = commands\n    .filter(command => !command.startsWith('__vitest'))\n    .map((command) => {\n      return `    [\"${command}\"]: (...args) => __vitest_browser_runner__.commands.triggerCommand(\"${command}\", args),`\n    })\n    .join('\\n')\n\n  const userEventNonProviderImport = await getUserEventImport(\n    provider,\n    this.resolve.bind(this),\n  )\n  const distContextPath = slash(`/@fs/${resolve(__dirname, 'context.js')}`)\n\n  return `","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/node/plugins/pluginContext.ts#L32-L68","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nexport default defineConfig({\n  test: { browser: { enabled: true, name: 'chromium' } },\n})\n\n// after\nexport default defineConfig({\n  test: {\n    browser: {\n      enabled: true,\n      name: 'chromium',\n      provider: 'playwright',\n    },\n  },\n})","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\nimport { resolve } from 'pathe'\n\nfunction assertProviderConfigured(config: { browser?: { provider?: { name?: string } | string } }): void {\n  const name = typeof config.browser?.provider === 'string'\n    ? config.browser.provider\n    : config.browser?.provider?.name\n  if (!name) {\n    throw new Error('test.browser.provider must be set (e.g. \"playwright\") before importing vitest/browser')\n  }\n}","typeGuard":"const hasProviderName = (c: { browser?: { provider?: { name?: string } | string } }): boolean => {\n  const p = c.browser?.provider\n  return typeof p === 'string' ? !!p : !!p?.name\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["browser-provider","configuration","virtual-module","bug"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}