Skip to content

fix: do not throw when browser mode is used without explicit projects (#9801) - #9938

Closed
oilater wants to merge 8 commits into
vitest-dev:mainfrom
hamsurang:fix/9801-allow-browser-without-projects
Closed

oilater wants to merge 8 commits into
vitest-dev:mainfrom
hamsurang:fix/9801-allow-browser-without-projects

Conversation

@oilater

@oilater oilater commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Resolves #9801

This PR fixes an issue where Vitest throws an incorrect validation error when browser mode is enabled without an explicit config.projects, even if valid browser.instances are provided.

Implementation

Updated the browser validation logic to distinguish between workspace and non-workspace configurations.

  • When config.projects is not defined, browser mode is allowed as long as valid browser.instances are provided.
  • When using a workspace, validation still ensures that at least one project has browser mode enabled.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify

netlify Bot commented Mar 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e319153
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d7da561ef2410008d94e68
😎 Deploy Preview https://deploy-preview-9938--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@oilater oilater closed this Mar 21, 2026
@oilater oilater reopened this Mar 21, 2026
Comment thread packages/vitest/src/node/core.ts Outdated
if (this._cliOptions.browser?.enabled) {
const browserProjects = this.projects.filter(p => p.config.browser.enabled)
if (!browserProjects.length) {
if (!browserProjects.length && !this.config.browser?.instances?.length) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed because instances inject new projects

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in c6ad238 !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheremet-va Could you review this when you have a chance?

@oilater

oilater commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor Author

I reverted my previous workaround

When no browser section exists in the config file, resolved.browser is falsy in resolveConfig,
so CLI/API browser options are never merged and instances never reach resolveBrowserProjects.

So I fixed this by allowing the merge when resolving the root config (resolved.browser || vitest.vite?.config === viteConfig), restoring browser options only for the root while keeping workspace isolation intact.

Also added a fallback for instance.name since CLI/API-only instances bypass the configResolved hook. Added tests as well.

I'm not sure this is the most fundamental fix, but let me know what you think.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@oilater
oilater requested a review from sheremet-va April 9, 2026 16:45
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startVitest + browser mode crashing with Vitest received --browser flag, but no project had a browser configuration.

2 participants