Can't resolve '@mswjs/interceptors/lib/interceptors/ClientRequest'
See original GitHub issuePrerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn’t contain the answer to my issue
Environment check
- I’m using the latest
msw
version - I’m using Node.js version 14 or higher
Browsers
NODE 16/18
Reproduction repository
https://github.com/coinbase/rest-hooks/tree/a3963b2618981992bab115a8e8543abdb9cdc655/website
Gonna revert MSW upgrade to make this work so master will no longer have this problem.
Reproduction steps
- clone repo above
- git checkout a3963b2618981992bab115a8e8543abdb9cdc655
- navigate to website folder
- yarn install
- yarn start
- observe error in cli as well as opened browser tab
Current behavior
ERROR in ./node_modules/msw/lib/node/index.mjs 45:0-94
Module not found: Error: Can't resolve '@mswjs/interceptors/lib/interceptors/ClientRequest' in '/home/ntucker/src/rest-hooks/website/node_modules/msw/lib/node'
Did you mean 'index.js'?
BREAKING CHANGE: The request '@mswjs/interceptors/lib/interceptors/ClientRequest' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
https://github.com/mswjs/msw/pull/1247 breaks in node versions that support ESM
Expected behavior
To fix this - the ESM version of MSW must be explicit about file extensions. Otherwise it is by definition incorrectly built. If this cannot be done you should not ship a custom ESM version as this is incorrect. The only reason it would work is if it is used by a system that doesn’t enforce fully (webpack). However this will break in fully-spec compliant things like node.
More simply:
import '@mswjs/interceptors/lib/interceptors/ClientRequest'
=> import '@mswjs/interceptors/lib/interceptors/ClientRequest.mjs'
Issue Analytics
- State:
- Created a year ago
- Reactions:35
- Comments:28 (11 by maintainers)
Top GitHub Comments
https://github.com/mswjs/msw/issues/1267#issuecomment-1297776977
FYI the issue with
bufferUtils
still occurs in0.48.0
Workaround: downgrade to
0.46.1