❯ node not-working.mjs
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:778:13)
at FetchInterceptor.<anonymous> (/Users/gerbenneven/project/msw-fetch-URL-invalid/node_modules/.pnpm/@mswjs+interceptors@0.17.10/node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:116:38)
at step (/Users/gerbenneven/projects/msw-fetch-URL-invalid/node_modules/.pnpm/@mswjs+interceptors@0.17.10/node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:59:23)
at Object.next (/Users/gerbenneven/projects/msw-fetch-URL-invalid/node_modules/.pnpm/@mswjs+interceptors@0.17.10/node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:40:53)
at fulfilled (/Users/gerbenneven/projects/msw-fetch-URL-invalid/node_modules/.pnpm/@mswjs+interceptors@0.17.10/node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:31:58) {
input: 'undefined',
code: 'ERR_INVALID_URL'
}
Node.js v20.6.1
fetch
supports being called with an instance ofURL
:However with
msw@1.3.3
this breaks:Repro URL: https://github.com/gerbyzation/msw-fetch-url-invalid
From what I can tell this is the offending line: https://github.com/mswjs/interceptors/blob/0c2f79db35b13a2db2dd9c5614a23b808d623220/src/interceptors/fetch/index.ts#L43
When
input
is a URL instance it's not a string, so usesinput.url
which evaluates to undefined.Note that this is from the source of 0.17.8 as 0.17.9 & 0.17.10 have no git tags associated, the code is practically the same.