-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Describe the bug
I get a Cannot access 'browser' before initialization error when running Vitest Browser Mode. The error came after updating to Vitest 3.1.1
13:52:14 [vite] (ssr) Error when evaluating SSR module /node_modules/@sveltejs/kit/src/runtime/control.js: Cannot access 'browser' before initialization
Plugin: vitest:mocks
File: /home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/@sveltejs/kit/src/runtime/control.js
at Object.filter (file:///home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:10506:45)
at filter (file:///home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:9085:20)
at TransformPluginContext.transform (file:///home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/@vitest/mocker/dist/node.js:722:9)
at EnvironmentPluginContainer.transform (file:///home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/vite/dist/node/chunks/dep-DrOo5SEf.js:47726:19)
at async loadAndTransform (file:///home/projects/sveltejs-kit-template-default-lck3k5rf/node_modules/vite/dist/node/chunks/dep-DrOo5SEf.js:41383:27)
Reproduction
https://stackblitz.com/edit/vitest-cannot-access-browser?file=vitest.workspace.ts
Created like this:
- New StackBlitz from SvelteKit template
npx sv addand selectvitestnpx init vitest browser:
✔ Choose a language for your tests › TypeScript
✔ Choose a browser provider. Vitest will use its API to control the testing environment › playwright
✔ Choose a browser › chromium
✔ Choose your framework › svelte
✔ Install Playwright browsers (can be done manually via 'pnpm exec playwright install')? … yesnpm run vitest:browser
I get the same error locally in my Dev Container, so I don't think it is due to issues with Playwright and StackBlitz.
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitest/browser: ^3.1.1 => 3.1.1
playwright: ^1.51.1 => 1.51.1
vite: ^6.0.0 => 6.2.4
vitest: ^3.0.0 => 3.1.1
vitest-browser-svelte: ^0.1.0 => 0.1.0Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Stadly, davidglivar and Dbuggerx