NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm, #2889 most downloaded on npm
The industry standard for API mocking in JavaScript.
Latest stable
3.0.4
Last release 16 days ago
06 Nov 2026
Release timing varies
gaps range from 8 days to 3 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
342 releases · first in 2018
Drag across the ruler to compare, or tap a release to open it.
transfer mocked response as ArrayBuffer to the worker
## v0.44.1 (2022-07-14) ### Bug Fixes - super call stack overflow
`req.body` is deprecated. Please use explicit request body reading methods: req.text(), req.json(), req.arrayBuffer() (other methods, like req.formDat…
Your coding agent can read these notes before it upgrades. Set up the MCP server →
req.destination default value is now "" (empty string), previously "document".req.redirect default value is now ""follow", previously "manual".parseIsomorphicRequest() function (#1316). Please use MockedRequest class instead.req instance:
req.priority, indicates a priority of request relatively to other requests (default "auto");req.text(), reads the request body as plain text;req.json(), reads the request body as JSON;req.arrayBuffer(), reads the request body as ArrayBuffer;req.clone(), clones a request instance (i.e. so its body could be read multiple times).req.body is deprecated. Please use explicit request body reading methods: req.text(), req.json(), req.arrayBuffer() (other methods, like req.formData() are currently not supported).rest.post('/user', async (req, res, ctx) => {
const newUser = await req.json()
})
req.bodyis still present for compatibility reasons but will be removed in the next releases.
support multiple response cookies using "ctx.cookie()"
send mocked response body as ReadableStream to the worker
apply response delay conditionally
setupServer: reference interceptors to support fast refresh
add "ctx.field()" for GraphQL responses
upgrade to @mswjs/interceptors 0.16
## v0.41.1 (2022-05-27) ### Bug Fixes - support typescript 4.7
improve module formats (cjs, esm, iife)
support typescript 4.4.x, 4.5.x, 4.6.x
## v0.40.1 (2022-05-19) ### Bug Fixes - support typescript 4.3.x
Returning undefined, or early returns, from response resolvers, now does not perform request as-is, and is instead treated as a handler that didn't do
undefined, or early returns, from response resolvers, now does not perform request as-is, and is instead treated as a handler that didn't do anything. Please return req.passthrough() if you wish to bypass a request.rest.get('/resource', (req, res, ctx) => {
// I want to perform this intercepted request as-is.
- return
+ return req.passthrough()
})
parseIsomorphicRequest: bypassing cookies properly
add fallback for "_defaultAgent" in ClientRequest
update @mswjs/interceptors to 0.13.5
handleRequest: bypass request only if "x-msw-bypass" header equals "true"
update to @mswjs/interceptors 0.13.3 (#1095) (e288d18), closes #1102
onUnhandledRequest in a custom callback (https://github.com/mswjs/msw/pull/1096):worker.start({
onUnhandledRequest(request, print) {
// Ignore unhandled warnings/errors from asset requests.
if (request.url.href.includes('/assets/') {
return
}
// Otherwise, execute the default warning/error/ strategy.
print.warning() // or "print.error()"
}
})
allow variables inference in GraphQLRequest
parse request body with letter case Content-Type header value
Fixes an issue that resulted in port numbers being treated as path parameters (#1036, #1028).
Fixes an issue that resulted in the CORS policy violation due to the library appending the x-msw-request-id request header (#713, #1022, #1024).
x-msw-request-id request header (#713, #1022, #1024).x-msw-request-id header on the request (#1024). Relies on the request.id set by the interceptors (Node.js) or the requestId generated by the worker (browser).Fixes an issue that resulted in the "TypeError: expected.toLowerCase() is not a function" exception when using the rest.all() request handler (#1020,
rest.all() request handler (#1020, #1021).Fixes an issue that resulted in the "SyntaxError: Invalid group specified name" exception in Safari (#1018, #1019 ).
Uses path-to-regexp for URL matching (#691, #888). This makes the path matching experience identical to such in ExpressJS, and enabled various new fea
/foo/bar?);/foo/bar+).string | string[] (#999).RequestParams generic now follows the RequestBodyType generic, changing its order (#999):rest.post<RequestBodyType, RequestParams, ResponseBodyType>() {}
RequestParams type (#999). Please use the PathParams type instead.- import { RequestParams } from 'msw'
+ import { PathParams } from 'msw'
document.baseURI (previously location.origin) in a browser-like environments (#1007, #1008).rest.all() request handler (#896). This handler captures all REST API requests regardless of method.import { rest } from 'msw'
rest.all('/api/*', (req, res, ctx) => {
// Intercepts all requests to "/api/*"
// regardless of their method.
})
graphql.query('GetUser', (req, res, ctx) => {
return res(
ctx.extensions({
message: 'Mocked extension',
tracking: { version: '1.2.3' }
})
)
})
SetupWorkerApi and SetupServerApi from the browser and Node.js modules respectively (#994).typescript as a peerDependency to control supported TypeScript versions (#985).graphql.operation handler producing a warning unable to intercept anonymous operations (#918, #904).inquirer dependency version to 8.1.5 to propagate the fix for the Unexpected token “?” issue when using MSW CLI (#917).TypeError: Failed to execute 'XXX' on 'Response': body stream already read error when reading the original response body in the fallback mode (https://github.com/mswjs/interceptors/pull/152).@mswjs/cookies and @mswjs/interceptors as external packages so that their updates propagate to you automatically upon new installations of msw.The Life-cycle events are now exposed from the .events property on the worker/server (#868).
.events property on the worker/server (#868).-worker.on('request:start', listener)
+worker.events.on('request:start', listener)
-server.on('response:mocked', listener)
+server.events.on('response:mocked', listener)
.removeListener() and .removeAllListeners() methods (#868).// Removes all life-cycle event listeners you've attached to this server instance.
server.events.removeAllListeners()
onUnhandledRequest option now throws an exception to halt running tests (#856).@mswjs/interceptors package to propagate the xmldom security update (#876).Improves error messages produces by the worker (#841, #847).
Fixes an issue when some messages from the library were ill-formatted (#844, #850).
Fixes an issue that resulted in the "color: inherit" being present in each request log in the browser's console (#842, #843).
Fixes an issue that resulted in the NextJS development server becoming unresponsive due to cancelled SSR from webpack HMR (#834, #837).
Setting a Cookie/Set-Cookie response headers via ctx.set now produces a type violation (#819). Please use ctx.cookie instead.
Cookie/Set-Cookie response headers via ctx.set now produces a type violation (#819). Please use ctx.cookie instead.resolutionContext option on handleRequest API to specify the baseUrl for all relative request handler URLs (#830).Fixes an issue when calling setupServer in React Native thrown an exception for using it in the wrong environment (#827).
setupServer in React Native thrown an exception for using it in the wrong environment (#827).Exports internal utilities to be used in extensions (#824);
parseIsomorphicRequest()handleRequest()Fixes an issue that resulted in corrupted original response bodies if they were compressed with gzip (https://github.com/mswjs/interceptors/pull/136,
IncomingMessage body of the original response in Node.js (https://github.com/mswjs/interceptors/pull/140, #785).Fixes the setTimeout issue in Socket
setTimeout issue in Socket (https://github.com/mswjs/interceptors/pull/120, #812)Fixes the operability issue when used in React Native (#622, #808, #809, #810).
Nothing published for this version
Fixes an issue when the original HTTPS requests were not correctly performed in Node.js (#700, #797).
Supports generators as response resolvers (#720). ```js rest.get('/polling/:maxCount', function* (req, res, ctx) { const { count } = req.params let co
rest.get('/polling/:maxCount', function* (req, res, ctx) {
const { count } = req.params
let count = 0
while (count < req.params. maxCount) {
yield res(ctx.json({ count }))
}
return res(ctx.json({ done: true }))
})
ctx.cookie utility to the GraphQL handlers (#763).mockServiceWorker.js) now contains the library version number to improve its inspection and debugging across releases (#781).onUnhandledRequest default behavior (#740).The onUnhandledRequest option is set to "warn" by default (previously ”bypass") (#703).
onUnhandledRequest option is set to "warn" by default (previously ”bypass") (#703).npx msw init now recursively creates a non-existing worker directory (#699).setupServer (https://github.com/mswjs/interceptors/pull/116).xhrInstance.responseXML in Node.js (#715).Fixes an issue when req.params was undefined in case when request path had no parameters present (#682, #684). The req.params value is always an objec
req.params was undefined in case when request path had no parameters present (#682, #684). The req.params value is always an object, regardless if you have path parameters defined.Fixes the issue that resulted in the "Cannot read property 'id' of undefined" in iframe scenarios (#643, #645).
Content-Type header (#671).The response instance in the life-cycle events now handles response.headers as the Headers instance (#660).
response instance in the life-cycle events now handles response.headers as the Headers instance (#660).server.on('response:bypass', (res) => {
- res.headers['content-type']
+ res.headers.get('content-type')
})
setupServer no longer applies request interception immediately. Instead, it's applied when called server.listen() (#660).XMLHttpRequest in Node.js (https://github.com/mswjs/interceptors/pull/102).superagent (#632).Fixes a backward-compatibility issue of the DropFirstInTuple type used internally in compose.ts (#658).
DropFirstInTuple type used internally in compose.ts (#658).Exports the RestHandler class publicly.
RestHandler class publicly.Uncaught ReferenceError: process is not defined exception when calling worker.start() (#609, #629).PickLastInTuple type (#615, #627).TypeError: Object.fromEntries is not a function error when running MSW in Node.js v10 (#625, #633).typescript@4.2.2Rebuilds the Request Handler API from ground-up (#561). Does not introduce any breaking changes in how you use the handlers.
worker.start() will now reject in the case of any errors during the worker registration (#607).RestRequestType, use RestRequest instead.GraphQLMockedRequest, use GraphQLRequest instead.GraphQLMockedContext, use GraphQLContext instead.GraphQLRequestPayload, use GraphQLRequestBody instead.GraphQLRequestParsedResult, use ParsedGraphQLRequest instead.GraphQLResponseResolverMockedRequest type no longer have the params key (#561). Please use the RestRequest type to annotate REST API requests instead.msw.workerDirectory property in your package.json:{
"msw": {
"workerDirectory": "public"
}
}
Starting from this release, whenever you install msw, it will try to locate the msw.workerDirectory property in your package.json and copy the relevant worker script (mockServiceWorker.js) to that directory.
Whenever running msw init now, you will be prompted to save your public directory choice to package.json.
msw init you can pass the —save option to automatically save the public directory in your package.json for future worker updates (#606). You can alternatively use --no-save to bail out this step.response:* life-cycle events (#570).Nothing published for this version
Fixes an issue that resulted in GraphQL request handlers not annotating the mocked response structure based on the given generic type (#587).
res.once) affected multiple matching requests made in parallel (#583).OnUnhandledRequest type as the new UnhandledRequestStrategy type (#577).onUnhandledRequest option will now suggest similar request handlers based on the URL/operation name similarity (#560).
onUnhandledRequest option will now suggest similar request handlers based on the URL/operation name similarity (#560).Response instance for the response:* life-cycle event (#570).onUnhandledRequest: "error" option resulted in a thrown exception being gracefully handled by Axios (#544). The "error" value now prints to stderr directly instead of throwing an exception. An original request-related exception will become visible now as well.> This release introduces changes to the mockServiceWorker.js file. Please follow the instructions in the browser to update the worker file. Thank you
This release introduces changes to the
mockServiceWorker.jsfile. Please follow the instructions in the browser to update the worker file. Thank you.
ctx.delay() // random realistic response time
ctx.delay('real') // the same as `ctx.delay()`
ctx.delay('infinite') // infinite response time
ctx.delay(50) // explicit response delay (50ms)
[MSW] Mocking disabled message when calling worker.stop(). (#485, #493).Failed to construct 'Response': The status provided (0) is outside the range [200, 599]. exception caused by an opaque response on the page (#529, #564). MSW will now skip opaque responses during the life-cycle events handling. You will not get the response:bypass invoked upon an opaque response.ExecutionResult of graphql was not compatible with ctx.data and ctx.errors utilities (#522, #542).self instead of this in the worker script (#568).Adds Life-cycle events API (#482, docs).
Exports the RestContext type interface for public consumption (#524).
RestContext type interface for public consumption (#524).Publishes the library in IIFE format, allowing to use it from a tag (#507, #509).
<script> tag (#507, #509).Nothing published for this version
Ships with refined JSDoc support (#483). Most of the core functions and methods now include concise description, usage example, and a link to the docs
ctx.json context utility now always stringifies the response body (#468).
ctx.json context utility now always stringifies the response body (#468).Supports asynchronous response transformers (#465, #467).
import { ResponseTransformer, compose } from 'msw'
import base64Image from 'url-loader!../../fixtures/image.jpg'
async function jpeg(base64: string): Promise<ResponseTransformer> {
const buffer = await fetch(base64).then((res) => res.arrayBuffer())
return compose(
context.set('Content-Length', buffer.byteLength.toString()),
context.set('Content-Type', 'image/jpeg'),
context.body(buffer),
)
}
const worker = setupWorker(
rest.get('/image', async (req, res, ctx) => {
return res(await jpeg(base64Image))
}),
})
compose function (#467).import { compose } from 'msw'
One column per quarter.