-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
globalThis.__vitest_broser_runner__ is not accessible within the scope of web workers, so vite's dynamic import wrapping is breaking via:

Adding this hack to the top of the worker seems to fix the issue, but it's still a bug nonetheless:
Reproduction
I'm struggling to repro on StackBlitz due to browser mode incompatibilities on the web-based IDE.
Here's some links to my open source project where this applies:
- Repo
- worker file containing hacky fix - removing this one line causes the error to resurface when running tests.
To reproduce, start a web worker that contains a dynamic import...
// main.ts
const worker = new Worker(new URL('./worker-file.js', import.meta.url), { type: 'module' })
// ...
// worker-file.js
const asset = await import('any-package-or-file')System Info
System:
OS: macOS 14.6.1
CPU: (10) x64 Apple M1 Max
Memory: 24.88 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.17.0 - ~/.local/state/fnm_multishells/19453_1726068848957/bin/node
Yarn: 1.22.21 - /usr/local/bin/yarn
npm: 10.8.2 - ~/.local/state/fnm_multishells/19453_1726068848957/bin/npm
pnpm: 9.4.0 - /usr/local/bin/pnpm
bun: 1.1.26 - ~/.bun/bin/bun
Watchman: 2024.05.06.00 - /usr/local/bin/watchman
Browsers:
Brave Browser: 128.1.69.168
Safari: 17.6
npmPackages:
@vitest/browser: ^2.1.1 => 2.1.1
@vitest/coverage-v8: ^2.1.1 => 2.1.1
@vitest/ui: ^2.1.1 => 2.1.1
vitest: ^2.1.1 => 2.1.1Used Package Manager
pnpm
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
