{"record":{"id":"865552aeba2e6930","repo":"vitest-dev/vitest","slug":"vitest-browser-can-be-imported-only-inside-the-bro-865552","errorCode":null,"errorMessage":"vitest/browser can be imported only inside the Browser Mode. Your test is running in ${pool} pool. Make sure your regular tests are excluded from the \"test.include\" glob pattern.","messagePattern":"vitest/browser can be imported only inside the Browser Mode\\. Your test is running in (.+?) pool\\. Make sure your regular tests are excluded from the \"test\\.include\" glob pattern\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/browser/context.js","lineNumber":14,"sourceCode":"// Vitest resolves \"vitest/browser\" as a virtual module instead\n\n// fake exports for static analysis\nexport const page = null\nexport const server = null\nexport const userEvent = null\nexport const cdp = null\nexport const commands = null\nexport const locators = null\nexport const utils = null\n\nconst pool = globalThis.__vitest_worker__?.ctx?.pool\n\nthrow new Error(\n  // eslint-disable-next-line prefer-template\n  'vitest/browser can be imported only inside the Browser Mode. '\n  + (pool\n    ? `Your test is running in ${pool} pool. Make sure your regular tests are excluded from the \"test.include\" glob pattern.`\n    : 'Instead, it was imported outside of Vitest.'),\n)\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/browser/context.js#L1-L21","documentation":"The vitest/browser entry point (context.js) is designed to only load inside a browser-mode worker. At module-evaluation time it reads the worker pool name from globalThis.__vitest_worker__.ctx.pool. If a pool exists but is not the browser pool (e.g. 'forks' or 'threads'), this error fires with the pool name, telling you the test file was collected outside browser mode.","triggerScenarios":"A test file imports from 'vitest/browser' (using page, userEvent, locators, commands, etc.) but the test run uses the default forks/threads pool instead of the browser pool. Typically caused by the file matching test.include without browser-mode configuration.","commonSituations":"Adding browser tests to a project but forgetting to set `test.browser.enabled = true` or to scope browser imports to a separate project/config; the browser test file is also matched by the default test glob and runs in Node.","solutions":["Enable browser mode: set `test.browser.enabled = true` (and configure provider) in vitest.config.ts.","Exclude browser test files from the default (Node) test run via test.exclude, or use workspace projects to separate browser and Node configs.","Move browser-specific imports into files that are only collected under the browser project."],"exampleFix":"// before — single config, browser file runs under forks pool:\n// vitest.config.ts\nexport default defineConfig({ test: { } })\n\n// after — enable browser mode:\nexport default defineConfig({\n  test: { browser: { enabled: true, instances: [{ browser: 'chromium' }] } }\n})","handlingStrategy":"validation","validationCode":"const pool = globalThis.__vitest_worker__?.ctx?.pool\nif (pool !== 'browser') {\n  // don't import vitest/browser in this context\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scope browser test files to a dedicated project/config so they only run under the browser pool.","Set test.browser.enabled = true before importing vitest/browser.","Use test.exclude to keep browser files out of Node-pool runs."],"tags":["browser","config","pool","import-guard"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}