diff --git a/package.json b/package.json index 338e7dc5e..4d9708436 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,7 @@ "regenerator-runtime": "^0.13.9", "rimraf": "^3.0.2", "simple-git-hooks": "^2.8.0", + "statuses": "^2.0.0", "ts-jest": "26", "ts-loader": "^9.2.6", "ts-node": "^10.1.0", diff --git a/src/context/fetch.ts b/src/context/fetch.ts index a596d43d7..0121fdeb7 100644 --- a/src/context/fetch.ts +++ b/src/context/fetch.ts @@ -3,7 +3,12 @@ import { Headers } from 'headers-polyfill' import { MockedRequest } from '../utils/request/MockedRequest' const useFetch: (input: RequestInfo, init?: RequestInit) => Promise = - isNodeProcess() ? require('node-fetch') : window.fetch + isNodeProcess() + ? (input, init) => + import('node-fetch').then(({ default: nodeFetch }) => + (nodeFetch as unknown as typeof window.fetch)(input, init), + ) + : window.fetch export const augmentRequestInit = (requestInit: RequestInit): RequestInit => { const headers = new Headers(requestInit.headers) diff --git a/src/node/setupServer.ts b/src/node/setupServer.ts index f53011937..bb3067b99 100644 --- a/src/node/setupServer.ts +++ b/src/node/setupServer.ts @@ -1,5 +1,5 @@ -import { ClientRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/ClientRequest' -import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest' +import { ClientRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/ClientRequest/index.js' +import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest/index.js' import { RequestHandler } from '../handlers/RequestHandler' import { SetupServerApi } from './SetupServerApi' diff --git a/src/utils/matching/matchRequestUrl.ts b/src/utils/matching/matchRequestUrl.ts index c97466a44..8d5d25cfc 100644 --- a/src/utils/matching/matchRequestUrl.ts +++ b/src/utils/matching/matchRequestUrl.ts @@ -1,5 +1,5 @@ import { match } from 'path-to-regexp' -import { getCleanUrl } from '@mswjs/interceptors/lib/utils/getCleanUrl' +import { getCleanUrl } from '@mswjs/interceptors/lib/utils/getCleanUrl.js' import { normalizePath } from './normalizePath' export type Path = string | RegExp