question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve '@mswjs/interceptors/lib/interceptors/ClientRequest'

See original GitHub issue

Prerequisites

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

  1. clone repo above
  2. git checkout a3963b2618981992bab115a8e8543abdb9cdc655
  3. navigate to website folder
  4. yarn install
  5. yarn start
  6. 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:closed
  • Created a year ago
  • Reactions:35
  • Comments:28 (11 by maintainers)

github_iconTop GitHub Comments

10reactions
grzegorz-zadoracommented, Nov 8, 2022

https://github.com/mswjs/msw/issues/1267#issuecomment-1297776977

FYI the issue with bufferUtils still occurs in 0.48.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'node_modules/@mswjs/interceptors/lib/utils/bufferUtils' imported from node_modules/msw/lib/node/index.mjs
Did you mean to import @mswjs/interceptors/lib/utils/bufferUtils.js
8reactions
raulfdmcommented, Sep 7, 2022

Workaround: downgrade to 0.46.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

@mswjs/interceptors - npm
Low-level HTTP/HTTPS/XHR/fetch request interception library. ... Start using @mswjs/interceptors in your project by running `npm i ...
Read more >
if you want to include a polyfill, you need to: - add a fallback 'resolve ...
node_modules/@mswjs/interceptors/lib/interceptors/ClientRequest/NodeClientRequest.js 224:13-28 Module not found: Error: Can't resolve 'http' in ...
Read more >
Docusaurus 2 App trying to resolve dev dependencies
html Module not found: Error: Can't resolve 'util' in '/Users/danielcaldas/code/my-project/website/node_modules/@mswjs/interceptors/lib/ ...
Read more >
Update to 3.0 breaks component tests - headers-polyfill/lib
Patch Release This releases fixes the Cannot find module 'headers-polyfill/lib' error seen when using mock service worker (MSW) in tests or ...
Read more >
Mock Service Worker adopts a brand-new request interception ...
@mswjs/interceptors. Low-level HTTP/HTTPS/XHR/fetch request interception library. Intercepts any requests issued by: http.get ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found