{"id":"440bcb7bcac8c6f4","repo":"vitejs/vite","slug":"fetchabledevenvironment-dispatchfetch-must-recei","errorCode":null,"errorMessage":"FetchableDevEnvironment `dispatchFetch` must receive a `Request` object.","messagePattern":"FetchableDevEnvironment `dispatchFetch` must receive a `Request` object\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/server/environments/fetchableEnvironments.ts","lineNumber":50,"sourceCode":"): environment is FetchableDevEnvironment {\n  return environment instanceof FetchableDevEnvironment\n}\n\nclass FetchableDevEnvironment extends DevEnvironment {\n  private _handleRequest: (request: Request) => Promise<Response> | Response\n\n  constructor(\n    name: string,\n    config: ResolvedConfig,\n    context: FetchableDevEnvironmentContext,\n  ) {\n    super(name, config, context)\n    this._handleRequest = context.handleRequest\n  }\n\n  public async dispatchFetch(request: Request): Promise<Response> {\n    if (!(request instanceof Request)) {\n      throw new TypeError(\n        'FetchableDevEnvironment `dispatchFetch` must receive a `Request` object.',\n      )\n    }\n    const response = await this._handleRequest(request)\n    if (!(response instanceof Response)) {\n      throw new TypeError(\n        'FetchableDevEnvironment `context.handleRequest` must return a `Response` object.',\n      )\n    }\n    return response\n  }\n}\n\nexport type { FetchableDevEnvironment }\n","sourceCodeStart":32,"sourceCodeEnd":65,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/server/environments/fetchableEnvironments.ts#L32-L65","documentation":"FetchableDevEnvironment.dispatchFetch at fetchableEnvironments.ts:50 asserts that its argument is an instance of the global Request. Passing a plain object, a string URL, or a Request-like duck-typed value throws a TypeError before the request is dispatched to handleRequest.","triggerScenarios":"Calling env.dispatchFetch({ url }) or dispatchFetch(url) instead of dispatchFetch(new Request(url)); frameworks that construct request-shaped objects without the Request constructor; a polyfilled Request class that is not the same constructor as the global one dispatchFetch checks against.","commonSituations":"Adapter code that hand-rolls request objects; multiple Request constructors in play (undici vs global vs polyfill) so instanceof fails; tests passing plain objects.","solutions":["Always pass new Request(input, init) constructed from the global Request into dispatchFetch.","If you hold a different Request class, rebuild the request via new globalThis.Request(otherRequest.url, otherRequest) before dispatch.","Make sure there is exactly one Request constructor in the realm (avoid mixing undici's Request with the global under Node >= 18)."],"exampleFix":"// before\nawait env.dispatchFetch({ url: '/path', method: 'GET' })\n\n// after\nawait env.dispatchFetch(new Request('https://example/path'))","handlingStrategy":"type-guard","validationCode":"function assertRequest(value: unknown) {\n  if (!(value instanceof Request)) {\n    throw new TypeError('dispatchFetch requires a global Request instance')\n  }\n}","typeGuard":"function isRequest(value: unknown): value is Request {\n  return typeof Request !== 'undefined' && value instanceof Request\n}","tryCatchPattern":null,"preventionTips":["Always construct new Request(...) from the global Request before dispatchFetch.","Avoid mixing Request constructors (undici vs global) in the same realm.","Type the dispatchFetch parameter as Request so TS rejects plain objects."],"tags":["environment","fetch-api","type-guard","validation"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}