mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
16k stars 522 forks source link

Recieving `Network error` after moving to codegen msw handlers, various dependency upgrades and the addition of RTK query. #2174

Closed charlieforward9 closed 1 month ago

charlieforward9 commented 5 months ago

Prerequisites

Environment check

Node.js version

v18.18.2

Reproduction repository

TODO

Reproduction steps

TODO

Current behavior

We just moved all of our api calls into graphql-codegen'ed RTK query hooks. During the process, we updated our Amplify and MSW dependencies. We are using Vitest and try to stay on the latest stable version, currently 1.5.3. Looking to bump soon.

Now when I run my tests, the first few API calls will go through (auth, first query), but after the first query, subsequent queries will not be matched.

I have the server event callbacks showing that once the issue starts, I do not see any "request:start" event, and i ultimately get this error.

Error: Network error
        at fetchTransferHandler (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\core\src\clients\handlers\fetch.ts:24:10)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at retryMiddleware (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\core\src\clients\middleware\retry\middleware.ts:28:28)
        at userAgentMiddleware (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\core\src\clients\middleware\userAgent\middleware.ts:12:28)
        at Module.transferHandler (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\api-rest\src\apis\common\handler.ts:56:18)
        at job (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\api-rest\src\utils\createCancellableOperation.ts:25:14)
        at GraphQLAPIClass._graphql (C:\Users\charl\Documents\Github\Agroview2.0\node_modules\@aws-amplify\api-graphql\src\internals\InternalGraphQLAPI.ts:259:29)
        at C:\Users\charl\Documents\Github\Agroview2.0\src\core\store\api.ts:44:44
        at executeEndpoint (file:///C:/Users/charl/Documents/Github/Agroview2.0/node_modules/@reduxjs/toolkit/src/query/core/buildThunks.ts:226:18)
        at file:///C:/Users/charl/Documents/Github/Agroview2.0/node_modules/@reduxjs/toolkit/src/createAsyncThunk.ts:352:27

Expected behavior

Work as it did prior to the dependency and structure changes. No network errors for handled GraphQL operations.

I would love to provide more details if I could figure out where to start. With so many layers packed on top of one another, it will be quite a bit of work to attempt a reproduction, but I will do this if necessary, I just need some explanation on what COULD be happening to understand where to start reproducing.

CC: @sainaruufl

kettanaito commented 1 month ago

Hi, @charlieforward9. I cannot help much without the repo and reproduction steps, sorry.

One common root cause for a generic "Network error" was related to bugs in Undici. I recommend upgrading your Node.js to the latest version. If you can't, update to the latest version within your range (e.g. ^18.0.0). That will give you all the bugfixes to Undici that may be breaking your Node.js's fetch.

If you find more details, please share. Thanks.