> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codemod.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MSW v1 to v2 Migration

MSW v2 brings the biggest API change to the library since its inception. Alongside the new API, it includes various features, such as `ReadableStream` support, ESM-compatibility, and countless bug fixes.

Codemod supports a mostly automated MSW v2 upgrade experience. This page provides tips and resources you may need for a successful migration.

## Getting started

> [card] [MSW v2 Upgrade Guide](https://mswjs.io/docs/migrations/1.x-to-2.x/#codemods)

> [card] [MSW v2 Upgrade Recipe](https://go.codemod.com/msw-codemods)

## Migration Steps

**1. Installation**

```bash theme={null}
npm install msw@latest
```

**2. Run codemods**

Inside your project's root directory, run the [MSW v2 upgrade recipe](https://go.codemod.com/msw-codemods):

```bash theme={null}
npx codemod @mswjs/v2
```

**3. Fix false negatives**

The upgrade recipe does not change the signatures of MSW handlers, if they were called using a custom factory function, for example to provide more type-safety or else. For example, the following code will only be partially updated:

```Typescript theme={null}
export function mockFactory<T extends MyComplexType>(
export function mockFactory<T extends MyComplexType>(
    url: string,
    resolver: MyResolverType,
) {
    return rest.get(url, resolver);
}

const handlers = [
    mockFactory('/some/url', (req, res, ctx) => {
        return res(ctx.status(200));
    }),
];
```

Additionally, if you were using `req.body` in your interceptors, this codemod will blindly assume you want `await request.json()` instead of any other type. You will have to correct that manually.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.