fix(spy): point ESM namespace spy error to module mocking docs - #10707
Merged
sheremet-va merged 1 commit intoJul 29, 2026
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
The 'Cannot spy on export' error fires in Node too, but its message linked users to the browser-mode-only docs anchor (/guide/browser/#limitations). Point it at the environment-agnostic module mocking guide (/guide/mocking/modules#mocking-a-module) instead, matching the standard solution the maintainers recommend. Fixes vitest-dev#9467
ryandiginomad
force-pushed
the
fix/9467-spyon-esm-error-docs-link
branch
from
July 17, 2026 15:26
ccef521 to
231ca0b
Compare
Contributor
Author
|
Quick check-in on this one — it's been in the queue a couple of weeks. I've rebased it on main and CI is green. It's a small fix following the direction @sheremet-va outlined in #9467: the |
sheremet-va
approved these changes
Jul 29, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
The
Cannot spy on export "…". Module namespace is not configurable in ESMerror links users to a browser-mode-only docs anchor (/guide/browser/#limitations). But this error fires in Node too — the reproduction in the issue (vi.spyOn(lodash, 'after')) has nothing to do with browser mode, so the link sends Node users somewhere irrelevant.This points the message at the environment-agnostic module mocking guide (
/guide/mocking/modules#mocking-a-module) instead — the standardvi.mock(path, { spy: true })solution — following @sheremet-va's steer in the issue to "lean into the standard" rather than suggest a mode-specific config. The message body and the guard are unchanged; only the link moves. No environment branching is added.I used the
#mocking-a-modulesection anchor (not the bare page) to match the deep-linking convention already used for the sibling module-mocking error inpackages/mocker/src/node/hoistMocks.ts.Resolves #9467
Tests
Verified locally (
fixreverted → test fails,fixapplied → passes):test/unit): added a regression test invi.spyOn() edge casesthat fakes a non-configurable ESM namespace and asserts the message points at the mocking guide and not at/guide/browser. This is the path the browser snapshot test didn't cover.test/browser): updated the existing inline snapshot to the new link.Open questions for maintainers
{ spy: true }remedy on the target page currently sits inside a "Browser Mode Support" danger callout — a Node reader landing there might still hesitate. Happy to open a small follow-up to make that section's framing environment-agnostic if you'd like, but kept it out of this PR to keep the change minimal.vi.mock(path, { spy: true })hint directly, I can do that too — just wanted to avoid over-reaching (the earlier chore: improve spyOn ESM namespace error guidance #9505 went that route).🤖 AI assistance
Developed with Claude Code. I diagnosed the throw site, verified the docs anchor lands on the right content, and confirmed the fix with a local red→green test run. I've reviewed every line of this diff.