Cannot read properties of undefined (reading 'navigator') when using @vitest/browser
#6187
Closed
6 tasks done
Labels
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
When running vitest inside a mocha test suite, the error "Cannot read properties of undefined (reading 'navigator')" is thrown from a global
afterEach
handler registered by@vitest/browser
.For example:
I've investigated this somewhat, and vitest includes some reset logic for mocking in its index.js bundle. However, this should not be included in the server-side code as it assumes running in the browser (as it tries to read from
globalThis.window.navigator
).I cannot find this code inside the vitest monorepo, so I think it is a dependency that gets bundled in via rollup.
Code that causes the issue
Reproduction
I've created a simple reproduction repo for this:
vitest-issue.zip
The basics is that I've created a simple mocha test that starts and stops vitest. In the vitest config I've configured browser mode.
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: