mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
539 stars 123 forks source link

Can't resolve `_http_common` when using `msw@2.4.4` #629

Closed kevva closed 3 weeks ago

kevva commented 3 weeks ago

When using msw@2.4.4, I get the following error when trying to build a TS package that depends on it:

Module not found: Can't resolve '_http_common'

The paths mapping obviously doesn't exist when published so it needs to be resolved correctly when building this module before publishing, not sure why tsup doesn't fix that.

kettanaito commented 3 weeks ago

Hi. This isn't path mapping. _http_common is a built-in module in Node.js.

What version of Node.js are you using? Please note this library, and the entire MSW toolchain, requires Node.js v18+ to work.

kevva commented 3 weeks ago

@kettanaito, I'm using v22.8.0. Can you please link where _http_common is documented? http is a core Node.js module, but I've never seen _http_common. You're importing the RequestHeadersCompleteCallback and ResponseHeadersCompleteCallback types from there as well which doesn't exist anywhere in the Node.js codebase so I'm curious how that would work. I think it might've existed in undici at one point but it's removed from there as well.

Like I mentioned in the issue description, this might have something to do with the mapping and tsup (the types stops working when removing it at least). Also, the file probably needs to be added to files in package.json as well.

kevva commented 3 weeks ago

It also doesn't make sense to me why you are importing and using interfaces/types from a .d.ts file. It's for the consumers of packages, not to be consumed by the package itself. Why don't you just move the _http_common.d.ts file to src/interceptors/ClientRequest somewhere (since it's only used there) and rename it to a .ts file? That would fix this issue.

kevva commented 3 weeks ago

~Here is a reproducable example using a Next.js app without any config. I guess it'd work if moving _http_common to externals so it's not bundled in any way but definitely not how it's expected to work.~

Actually, it's probably how it's expected to work since using _http_common outside works fine as you say. I couldn't find it documented anywhere though so was a bit sceptical.

image
kettanaito commented 2 weeks ago

This has been fixed by #633. Please upgrade and verify.