skip to Main Content

I am following the example here:

https://testing-library.com/docs/react-testing-library/example-intro/

At the "Step-By-Step" section under "Imports" it says this:

// import dependencies
import React from 'react'

// import API mocking utilities from Mock Service Worker
import {rest} from 'msw'
import {setupServer} from 'msw/node'

At first, I received an error for this line:

import {setupServer} from 'msw/node'

But I ran the command:

npm install msw@latest

And that fixed that particular error. However, this error:

Module '"msw"' has no exported member 'rest'. ts(2305)

At the line:

import { rest } from 'msw'

where "rest" is spelled out, still remains.

This is what I am working with:

  • node: 18.17.1
  • npm: 9.8.1
  • typescript: 5.3.3

I appear to have the latest ‘msw’ as I performed that "install msw@latest", but I cannot figure out this error.

2

Answers


  1. try to use " import { http } from ‘msw’ " instead

    https://mswjs.io/docs/migrations/1.x-to-2.x/

    Login or Signup to reply.
  2. The newest MSW version has deprecated rest in favor of http.

    The solution then should be to update your import to:

    import { http } from ‘msw’;

    From there you can follow the migration guides at this link: https://mswjs.io/docs/migrations/1.x-to-2.x/ to ensure you’re properly setting up your mocks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search