Skip to content

fix(mocker): support both MSW v2 and v3 - #11412

Closed
EskiMojo14 wants to merge 1 commit into
vitest-dev:mainfrom
EskiMojo14:msw-v3
Closed

EskiMojo14 wants to merge 1 commit into
vitest-dev:mainfrom
EskiMojo14:msw-v3

Conversation

@EskiMojo14

@EskiMojo14 EskiMojo14 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

MSW v3 renames the msw/core/http entry point to msw/http, which is used by @vitest/mocker. This PR takes the more conservative approach of allowing both v2 and v3 (using Promise.any on the dynamic imports and adjusting the peer dependency), meaning that this shouldn't be a breaking change.

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. (existing tests fail with msw v3 installed without these changes)
  • 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 Sep 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7d6c064
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ac3621d21119d0008781e77
😎 Deploy Preview https://deploy-preview-11412--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@EskiMojo14

Copy link
Copy Markdown
Contributor Author

hmm, even with the vite-ignore, vite is trying to eagerly resolve the import and failing 🤔
unless the vite-ignore isn't applying because of the ts-expect-error comment, which would be a pain

i assume a breaking change to only support v3 would be undesirable?

@fschmutz

fschmutz commented Oct 4, 2026

Copy link
Copy Markdown

Tried this branch (35f0718) downstream: @vitest/mocker built from the PR and packed, vitest 5.0.3 + @vitest/browser-playwright 5.0.3, msw 3.0.2, vite 8.3.2, Node 26.3.0, pnpm 11.

  • pnpm peers check: the "unmet peer msw ^2.4.9 (installed 3.0.2)" warning is gone; our 125 browser-mode tests still pass (they use the vite-plugin interceptor, not the MSW one).
  • Vite's dev transform of dist/browser.js still fails with "./core/http" is not exported ... from package msw, same as the e2e jobs here. The @vite-ignore comment is stripped from the built dist, and even import(/* @vite-ignore */ 'msw/core/http') is still resolved because the specifier is a string literal. In a quick check, a non-literal specifier (const s = 'msw/core/http'; import(/* @vite-ignore */ s)) passed the transform; I did not verify its runtime behaviour with msw v2.

@EskiMojo14

Copy link
Copy Markdown
Contributor Author

test failures are now unrelated, and appear on main as well (introduced by #11417)

related tests and typechecking are passing

EskiMojo14 added a commit to open-circle/schema-benchmarks that referenced this pull request Oct 5, 2026
@sheremet-va

Copy link
Copy Markdown
Member

Fixed in #11482

@sheremet-va sheremet-va closed this Oct 5, 2026
@EskiMojo14
EskiMojo14 deleted the msw-v3 branch October 5, 2026 12:46
@sxflynn

sxflynn commented Oct 7, 2026

Copy link
Copy Markdown

Which release of vitest will have this change?

EskiMojo14 added a commit to open-circle/schema-benchmarks that referenced this pull request Oct 7, 2026
EskiMojo14 added a commit to open-circle/schema-benchmarks that referenced this pull request Oct 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 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.

4 participants