Closed cubeghost closed 4 months ago
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node does not have a default export for node built-ins, node's actual runtime does, but its community maintained types don't.
https://github.com/mswjs/msw/issues/2049#issuecomment-2002640920 is a very hot take, node's actual runtime doesn't care, DT says to import all named exports and doesn't support the default, nock works with both, msw doesn't.
Ultimately, if import { get } from 'node:http'
is a valid way of getting the get export from a node builtin than so is import * as http from 'node:http'; http.get
and the way it's written at the moment is within the node's community driven DT types.
What happened?
Request mocking library
msw
is unable to intercept requests when thehttp
orhttps
libraries are imported using namespace style imports, for exampleimport * as http from 'node:http'
instead ofimport http from 'node:http'
. https://github.com/mswjs/msw/issues/2049I could use
nock
, butmsw
is what my team uses elsewhere and it's what's recommended for use withvitest
.In my replicated example, I can confirm that changing the import style in
runtime/node/fetch_jwks.ts
allows the request to be mocked and the test to pass.Version
5.2.4
Runtime
Node.js
Runtime Details
Node 18 & 20, vitest 1.5.3, msw 2.2.14
Code to reproduce
Required