You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ESM: import { request } from 'node:https' bypasses interception until the patched https.request is called once #2824
npm install
npm run repro # node repro.mjs
npm run workaround # node repro.mjs --sync (calls module.syncBuiltinESMExports() after server.listen())
Current behavior
In ES module, request imported by name from node:https isn't intercepted: the request goes to the network.
1. named import : ENOTFOUND
2. default https.request : {"intercepted":true}
3. named import again : {"intercepted":true}
It's order-dependent: once the patched https.request (default import) has been called, later named-import calls are intercepted too, so the first call through a named import is the one that leaks.
Real-world case: aws-jwt-verify ESM build does import { request } from "https" to fetch JWKS, so a test that mocks the JWKS endpoint fails until something else makes a request first.
Named ESM imports of builtins are bound to a separate copy of the module's exports, which Node only refreshes on module.syncBuiltinESMExports(). Patching https.request on the CommonJS exports doesn't reach it. Same report: mswjs/interceptors#201 (closed, unresolved).
Expected behavior
Named imports are intercepted from the first request, like the default import.
Calling syncBuiltinESMExports() from node:module right after applying the patches (and again after restoring them) fixes it: with --sync, all three requests are intercepted. Could the interceptor do that itself?
Hi! I reproduced this on current mswjs/interceptors main (31cc4c3b, 0.45.11) with Node 22.20.0 on Windows.
It affects the first call through native ESM named imports of all four HTTP functions: http.request, http.get, https.request, and https.get. My tests use a local HTTP/HTTPS server: without the change, they receive the real server's response instead of the mocked response. The fixture is loaded by Node through createRequire, so Vitest's import transformation cannot hide the stale bindings.
I have a local change in ClientRequestInterceptor that calls syncBuiltinESMExports() after installing the patches and again after restoring them during disposal. Five focused tests pass (four request cases plus binding restoration). A separate native Node script also verifies two apply/dispose cycles and successful real requests after disposal.
Validation: 267 HTTP tests passed, 3 skipped; 26 ClientRequest unit tests passed; TypeScript and the Node build passed. Three other HTTP test files fail on this Windows setup with and without the change (Unix socket setup, a child-process launch, and a multipart passthrough ECONNRESET).
Would you welcome this regression test and fix as a PR in mswjs/interceptors, linked to this issue?
Investigation, tests, fix, and this comment were prepared with OpenAI Codex assistance. The checks above were executed locally.
Activity
Hugo510 commentedon Nov 3, 2026
Hi! I reproduced this on current
mswjs/interceptorsmain (31cc4c3b, 0.45.11) with Node 22.20.0 on Windows.It affects the first call through native ESM named imports of all four HTTP functions:
http.request,http.get,https.request, andhttps.get. My tests use a local HTTP/HTTPS server: without the change, they receive the real server's response instead of the mocked response. The fixture is loaded by Node throughcreateRequire, so Vitest's import transformation cannot hide the stale bindings.I have a local change in
ClientRequestInterceptorthat callssyncBuiltinESMExports()after installing the patches and again after restoring them during disposal. Five focused tests pass (four request cases plus binding restoration). A separate native Node script also verifies two apply/dispose cycles and successful real requests after disposal.Validation: 267 HTTP tests passed, 3 skipped; 26 ClientRequest unit tests passed; TypeScript and the Node build passed. Three other HTTP test files fail on this Windows setup with and without the change (Unix socket setup, a child-process launch, and a multipart passthrough ECONNRESET).
Would you welcome this regression test and fix as a PR in
mswjs/interceptors, linked to this issue?Investigation, tests, fix, and this comment were prepared with OpenAI Codex assistance. The checks above were executed locally.
AndrewBoklashko commentedon Nov 21, 2026
Hi MSW team
Any feedback on this?