Packages

msw

3.0.7 · 18 Nov 2026MIT36.1M / weekRepositoryHomepagenpmAtom feed

Your version

2.0.0

major23 Oct 2023Where it was published

2.15.0 is the newest release of 2.x.

In short

12 breaking9 new10 fixed3 changed1 internal

  • Breaking

    This release is a BREAKING CHANGE.

  • Breaking

    Drops support for Node.js 16. Please upgrade to Node.js 18 or later to use the global Fetch API.

  • Breaking

    Drops support for TypeScript < 4.7.

  • Breaking

    All browser-side exports, like setupWorker, SetupWorkerApi, etc., must be imported from msw/browser now.

  • Breaking

    Renames the rest object to http (rest.get -> http.get).

  • Breaking

    Response resolver call signature is no longer (req, res, ctx) => res() but instead ({ request }) => new Response().

  • Breaking

    res.once() is removed in favor of the { once: boolean } option on the request handler.

  • Breaking

    Replaces the .printHandlers() method with .listHandlers().

Release note

Important

This release is a BREAKING CHANGE. Please follow the Migration guidelines to upgrade. This release took a lot of effort to make, and I expect a bit of that effort on your part while upgrading. Most of the changes are mechanical, and a simple Find/Replace All will get you a long way. For the rest of it, you will learn how to handle requests and responses using the standard JavaScript API. Thank you!

Breaking changes

  • Breaking

    Drops support for Node.js 16. Please upgrade to Node.js 18 or later to use the global Fetch API.

  • Breaking

    Drops support for TypeScript < 4.7.

  • Breaking

    All browser-side exports, like setupWorker, SetupWorkerApi, etc., must be imported from msw/browser now.

  • Breaking

    Renames the rest object to http (rest.get -> http.get).

  • Breaking

    Response resolver call signature is no longer (req, res, ctx) => res() but instead ({ request }) => new Response().

  • Breaking

    The following exports are removed due to no longer being needed:

    • response

    • context and related exports (defaultContext, restContext, graphqlContext).

    • compose and createResponseComposition

  • Breaking

    res.once() is removed in favor of the { once: boolean } option on the request handler.

  • Breaking

    Replaces the .printHandlers() method with .listHandlers().

  • Breaking

    Removes the NetworkError class in favor of the standard Response.error().

  • Breaking

    Moves request error handling from the worker thread to the client thread.

  • Breaking

    Changes the call signature of the Life-cycle Events API to accept a single object argument.

  • Breaking

    Uses crypto.randomUUID() instead of Math.random() in the worker.

Features

  • Adopts Fetch API primitives. Represent intercepted requests and mocked responses as Request and Response instances respectively.

  • Supports Node.js v18.

  • Supports ReadableStream as a mocked response body.

  • Supports reading the intercepted request body as FormData.

  • Supports FormData as a mocked response body.

  • Uses File polyfill in Node.js.

  • Supports XMLHttpRequest “upload” events when responding with a mocked stream response.

  • Allows mocking a network error once using the { once: true } request handler option.

  • Makes the RequestHandler API public.

Bug fixes

  • Fixes the issue where the request body couldn’t be properly read as FormData.

  • Fixes a set of issues related to response patching when using the FormData response body.

  • Fixes the issue where URLSearchParams as the request body couldn’t be read.

  • Fixes the issue where a bypassed request’s referrerPolicy was reset to a different value than the original.

  • Fixes the wrong order of XMLHttpRequest events and readyState changes.

  • Fixes the issue when reading an XMLHttpRequest body of responseType equal to "arraybuffer" as an incorrect buffer (previously, always assumed to be a string).

  • Fixes the order of XMLHttpRequest events when the request fails.

  • Keeps XMLHttpRequest status equal to 0 until the request actually resolves.

  • Fixes the issue when the onload event callback was called twice for XMLHttpRequest.

  • Various improvements in Node.js network behavior compliance.

@dbritto-dev @ddolcimascolo @markwhitfeld @christoph-fricke @thepassle @piotr-cz @mattcosta7 @koddsson @dkobierski @ricardocosta @dxlbnl @zkochan @felipefreitag @weyert @95th @committomaster @Xayer @Kosai106 @colinsullivan @xmlking @thw0rted @lee-reinhardt @wKovacs64 @TeChn4K @cmolina @nickrttn @thomasbertet @mscottnelson @jonnedeprez @negabaro @the-ult @WesleyYue @cwagner22 @skvale @alawiii521 @csantos1113 @elliotgonzalez123 @committomaster @tsteckenborn @xxleyi @jonnedeprez @danny-does-stuff @lemcii @mattrodak @luisr-carrillo @lee-reinhardt @ealejandrootalvaro @tomdglenn91

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.