Skip to content

● Test suite failed to run TypeError: Cannot read properties of undefined (reading 'post') ...rest from msw not pointing the type definition even it is correclty imported from node_modules #2207

Answered by kettanaito
shruthi-monika asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @shruthi-monika.

It looks like you are using the latest MSW with the v1 handler syntax (rest.post).

That syntax has changed since v2.0. Please see https://mswjs.io/docs/migrations/1.x-to-2.x.

How to resolve this?

You have two options:

(Recommended) Option 1: Update your code

Follow the Migration guide I've mentioned before, and update your request handler to use the correct syntax (e.g. http.post). This includes how you declare mocked responses as well.

Option 2: Downgrade MSW

This is easier but not recommended option. If you downgrade to msw@^1, the error will be gone but you won't be able to use newest MSW features. v1 is in a readonly mode, don't use it.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants