MSW does not intercept requests when the node http(s) library is imported using * as #2049
Closed
4 tasks done
Labels
bug
Something isn't working
needs:triage
Issues that have not been investigated yet.
scope:node
Related to MSW running in Node
Prerequisites
Environment check
msw
versionNode.js version
v20.10.0
Reproduction repository
https://github.com/mickdekkers/issue-repro-msw-request-interception-https-import
Reproduction steps
npm i
node index.mjs
Current behavior
MSW does not intercept the request to
https://example.org
with the code in the repro.However, if you comment out the following line in
index.mjs
:And uncomment the following line:
// import https from "node:https";
Then run
node index.mjs
again, you'll see that MSW now intercepts the request as expected.Expected behavior
MSW should intercept requests regardless of how the node http(s) library is imported.
Additional info
node:http
library and sending a request tohttp://example.org
jose
library. The network request thatjose
sends to fetch a JWKS was not being intercepted. After exhausting all the likely causes, I eventually narrowed it down to the way it imports thenode:https
library. Relevant code: https://github.com/panva/jose/blob/v5.2.1/src/runtime/node/fetch_jwks.ts#L2The text was updated successfully, but these errors were encountered: