Comments (7)
In my case, I do see [MSW] Mocking enabled.
and the first server request is mocked but none of the consequent calls.
I have been trying to replicate this issue:
- using the latest version of Next https://codesandbox.io/p/devbox/next-msw-m58zwf?file=%2Fapp%2Fpage.tsx%3A14%2C1
- using an older version of Next https://codesandbox.io/p/devbox/older-next-msw-ms4tz5?file=%2Fsrc%2Fpages%2Findex.tsx%3A25%2C11
I was not able to replicate the failed to fetch error
but my local code the issue still persists
from msw.
I'm going to close this. Next.js doesn't work well with MSW at the moment. Until I have a fully functional example as confirmation of that, Next.js is not supported.
You can follow the progress of that example here:
mswjs/examples#101
The Next.js team has also reached out to me to help address the remaining issues on Next.js side, so I hope to post some updates soon.
from msw.
in my case, most time every request is ok when I login by form in the page, there's no request before I typing username/password and click to send the first request after msw mocked.
If I refresh the page after login, there's a request for getting user info when vue router navigation, I'll got the same error, the request is send soon after msw mocked. the following login out request is successed.
I try to downgrade to 2.0.14, erveything is ok.
btw, if set onUnhandledRequest
to bypass
, it only thrown axios
error, change to warn
, it may thrown msw error sometime.
from msw.
I'm seeing the same issue with with [email protected] on a React+Vite app. MSW does not appear to be initialized for the requests which are fired off as part of the initial page load.
This sort of looks like the symptoms reported in #1653 but the deferred render approach is not effective here as it was in 2.0.14.
Edit: The bug was mine -- I'm running fine with 2.1.2 now. The snippet in the deferred render comment linked above is missing an await
on the worker.start()
and that carried over to my code. Perhaps 2.0.14 is just slightly quicker to start and didn't affect my app in the same way despite not waiting on the start call.
from msw.
same problem for me as well in version 2.1.2
from msw.
In my case, I do see
[MSW] Mocking enabled.
and the first server request is mocked but none of the consequent calls.I have been trying to replicate this issue:
- using the latest version of Next https://codesandbox.io/p/devbox/next-msw-m58zwf?file=%2Fapp%2Fpage.tsx%3A14%2C1
- using an older version of Next https://codesandbox.io/p/devbox/older-next-msw-ms4tz5?file=%2Fsrc%2Fpages%2Findex.tsx%3A25%2C11
I was not able to replicate the
failed to fetch error
but my local code the issue still persists
@kettanaito I was able to replicate in the codesandbox links above, wherein the first load MSW intercepts the first call but after I refresh the browser, there is no more interception.
from msw.
For future reference found this post from @kettanaito on X
In summary, this is the state of Next.js + MSW right now:
- Server-side mocking is possible but your app won't pick up updates to the handlers unless you restart it;
- Client-side mocking is not possible.
https://twitter.com/kettanaito/status/1749496339556094316
from msw.
Related Issues (20)
- Trying to pull body in POST mocks breaks mocking HOT 6
- Error: [MSW] Failed to locate the Service Worker registration. HOT 1
- Issue when no response.url and request is undefined HOT 1
- msw/node unable to intercept requests from fetch in undici HOT 9
- request.formData() fails with vitest and file HOT 8
- Make bad "Network behavior overrides" more obvious HOT 1
- Optional path parameters do not match correctly HOT 4
- Always results in Network Error when using undici 6.x HOT 3
- Recieving `Network error` after moving to codegen msw handlers, various dependency upgrades and the addition of RTK query.
- Unclear how to throw an actual error HOT 1
- Axios fails to follow redirects from MSW mocked responses HOT 4
- FormData with file fails in with-jest HOT 2
- Native fetch is intercepted, but openapi-fetch call makes actual request HOT 5
- Cookie with path other than root not sent to handlers HOT 8
- intercepted request won't abort on node 20 w/ [email protected]
- List "graphql" as a peer dependency HOT 5
- Addition of Boundary() to setupServer() in react-native with help of AsyncLocalStorage alternative in RN HOT 1
- "TypeError: Failed to parse URL from [object Request]" with Vitest and Happy DOM HOT 2
- Cannot read properties of undefined (reading 'url') HOT 3
- v1: Add generic type to MockedRequest.passthrough() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msw.