vitest-dev / vitest-dev/vitest

Browser Mode: Vite warns Plugin "vitest:mocks:interceptor" defines Vite-specific hooks (configureServer) in a plugin returned from applyToEnvironment on every run

Open Beginner friendly
#11,276 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

With test.browser.enabled: true, every vitest run prints once:

Plugin "vitest:mocks:interceptor" defines Vite-specific hooks (configureServer) in a plugin returned from applyToEnvironment. These hooks will be ignored.

Cause: @vitest/browser adds interceptorPlugin({ registerWebSocketEvents: false }) (from @vitest/mocker) to the browser contribution, which vitest:browser:loader.applyToEnvironment returns for the client environment. The mocker's interceptorPlugin always defines configureServer (its body returns early when registerWebSocketEvents === false), and Vite 8's resolveEnvironmentPlugins warns for any config / configEnvironment / configureServer / configResolved hook on a plugin returned from applyToEnvironment. Tests and mocking work; the warning is noise on every run.
Suggested fix: attach configureServer only when registerWebSocketEvents !== false (packages/mocker/src/node/interceptorPlugin.ts), or strip the hook in the browser contribution.

I do not plan to submit a PR. Used Claude Code to generate this report.

Reproduction

Link to the GitHub repository with the Reproduction — npm install && npm test.

Bare config: one chromium instance via @vitest/browser-playwright, one passing test, no plugins.
Actual: The warning above is printed once per run.
Expected: no warning. (The same happens in a 200-file production suite; the minimal repo is the stripped-down version.)

System Info
System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 Intel(R) Core(TM) Ultra 7 265H
    Memory: 6.38 GB / 31.46 GB
Binaries:
    Node: 24.20.0 - C:\nvm4w\nodejs\node.EXE
    npm: 11.19.1 - C:\nvm4w\nodejs\npm.CMD
Browsers:
    Chrome: 152.0.7977.84
    Edge: Chromium (147.0.3912.72)
npmPackages:
    @vitejs/plugin-react: 6.1.1 => 6.1.1 
    @vitest/browser-playwright: 5.0.0 => 5.0.0 
    @vitest/coverage-v8: 5.0.0 => 5.0.0 
    @vitest/eslint-plugin: 1.6.27 => 1.6.27 
    @vitest/ui: 5.0.0 => 5.0.0 
    playwright: 1.63.0 => 1.63.0 
    vite: 8.3.0 => 8.3.0 
    vitest: 5.0.0 => 5.0.0 
    vitest-browser-react: 2.3.0 => 2.3.0
Used Package Manager

npm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/mocker/src/node/interceptorPlugin.ts and reproduce the warning using the linked browser reproduction with npm install && npm test. Review how configureServer is attached when registerWebSocketEvents is false; done means the browser-mode run completes without the Vite warning while tests and mocking continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.