msw: (v.0.42) Error - Invariant Violation: Failed to respond request: the "request" event has already been responded to

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Node.js version

v16.15.0

Reproduction repository

https://github.com/7iomka/next-with-msw-and-effector

Reproduction steps

yarn add msw@latest yarn dev

Current behavior

error - Invariant Violation: Failed to respond to "GET http://localhost:3000/backend-api/xxxx" request: the "request" event has already been responded to.
    at setupServerListener (************/node_modules/msw/lib/node/index.js:1249:17) {

Expected behavior

All works as in v0.38.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Hey, my pleasure, @M3kH! I’m happy we were able to find a solution that’s not entirely hacky. HMR is tricky, and it depends on the module evaluation, so certain modules are “preserved” while certain are re-evaluated. Funny how moving a class instantiation into a different module affects how that class will behave when under hot reload. If anything, the hot reload itself feels magical (perhaps too magical?).

That being said, if you like my work and would like for MSW to grow and improve, please consider sponsoring the project on GitHub. Let’s build sustainable open source together, where features and bug fixes don’t cost maintainer’s personal lives and time.

I’m getting it with https://github.com/vercel/next.js/tree/canary/examples/with-msw just by upgrading dependency to "msw": "^0.42.1",

This is so amazing thanks @kettanaito I was just setting up msw and facing this issue, you don’t know how many cuddles I will like to give you since the solution was away from just upgrading the package.

Thank you so much for the hard work and for the great project!

It was two test files running the mock server in parallel

I can confirm same problem, and this is not happening in 0.41.1

It started in our case with 0.42.0 and 0.42.1

having same issue here