fix(test): exclude @vitest/browser/context from vendor-aliases to fix missing server export#1110
Merged
fengmk2 merged 3 commits intovoidzero-dev:mainfrom Mar 23, 2026
Merged
Conversation
… missing server export
✅ Deploy Preview for viteplus-preview canceled.
|
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
fengmk2
approved these changes
Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the missing
serverexport from@vitest/browser/contextwhen using@storybook/addon-vitestwith vite-plus.resolve #1086
Root Cause
In vitest's browser mode,
@vitest/browser/contextis a virtual module, theBrowserContextplugin intercepts the bare specifier inresolveIdand returns dynamically generated code (viagenerateContextFile()) that includes theserverexport with command RPC proxies, config, platform info, etc.However, vite-plus injects a
vitest:vendor-aliasesplugin during re-packaging (inbuild.ts) that maps@vitest/*bare specifiers to static files in the dist directory.Both plugins use
enforce: 'pre', butvendor-aliasesis registered beforeBrowserContextin the plugin array.Since Vite executes same-enforce plugins in registration order,
vendor-aliasesresolves the bare specifier to the staticcontext.jsfile beforeBrowserContextever sees it.The static
context.jsonly exports{ cdp, createUserEvent, locators, page, utils }— it does not includeserver, because that's supposed to come from the virtual module.Normal flow (plain vitest — no vendor-aliases)
sequenceDiagram participant Browser participant ViteServer as Vite Browser Server participant BC as BrowserContext Plugin<br/>(resolveId) participant Gen as generateContextFile() Browser->>ViteServer: import "@vitest/browser/context" ViteServer->>BC: resolveId("@vitest/browser/context") BC-->>ViteServer: "\0vitest/browser" (virtual module ID) ViteServer->>BC: load("\0vitest/browser") BC->>Gen: generateContextFile() Gen-->>BC: Dynamic code with server, commands, config... BC-->>ViteServer: Virtual module source ViteServer-->>Browser: Module with { server, page, cdp, ... }Bug flow (vite-plus — vendor-aliases intercepts first)
sequenceDiagram participant Browser participant ViteServer as Vite Browser Server participant VA as vendor-aliases Plugin<br/>(resolveId) ← runs first participant BC as BrowserContext Plugin<br/>(resolveId) ← never called Browser->>ViteServer: import "@vitest/browser/context" ViteServer->>VA: resolveId("@vitest/browser/context") VA-->>ViteServer: "/path/to/dist/@vitest/browser/context.js" (static file) Note over BC: resolveId is never called<br/>because vendor-aliases already resolved it ViteServer-->>Browser: Static file (no server export) Browser->>Browser: SyntaxError: does not provide<br/>an export named 'server'Plugin registration order in the browser Vite server
Fix
Exclude
@vitest/browser/contextfrom thevendor-aliasesplugin'svendorMapduring re-packaging (build.ts).This allows the bare specifier to pass through to the
BrowserContextplugin, which correctly returns the virtual module with theserverexport.