Open dwjohnston opened 3 months ago
iirc msw does not support server components yet: https://github.com/mswjs/msw/issues/1644#issuecomment-2253097742
i could be wrong in saying that it does not support them, but as i understand it's not quite finalised yet.
@bitttttten thanks for pointing that out - it's informative.
Note though - the with-msw example as it is demonstates use with the pages router, not the app router.
The https://github.com/mswjs/msw/issues/1644 thread suggests that the issue is with how Next is monkey patching fetch - however I've also tried downgrading next to 12.3.4 (As I understand it, the use of native fetch was introduced in 13.0.0) but we see the same error.
Repro here:
I'll point out to anyone else who is stumbling upon this - a work around for this issue is to not use native fetch, use node-fetch or axios instead. However, this will mean that you will lose Next's data caching functionality
Verify canary release
Provide environment information
Which example does this report relate to?
with-msw
What browser are you using? (if relevant)
N/A
How are you deploying your application? (if relevant)
npm run dev
Describe the Bug
Running the
with-msw
example as is , using node 20.16 will show this error:This issue here https://github.com/vercel/next.js/issues/56608 appears to be refer to the same issue, and it mentions that it's an issue with Next now using native fetch and MSW having an issue with it.
I updated to msw@2.3.5 and the issue still exists. (see: https://github.com/dwjohnston/with-msw-repro/commit/3d959bea37baec2500e089cd24e1c161331cabcc)
It's worth mentioning this open issue here: https://github.com/mswjs/msw/issues/1340
Expected Behavior
At the very least the with-msw example should show some kind of instance of MSW working, and the documentation provide all the caveats and scenarios where it won't work.
To Reproduce
Access application at localhost:3000 and observe server rendering fail.