{"id":"dca8103fbc4e5e73","repo":"vitejs/vite","slug":"fetchabledevenvironment-requires-a-handlerequest","errorCode":null,"errorMessage":"FetchableDevEnvironment requires a `handleRequest` method during initialisation.","messagePattern":"FetchableDevEnvironment requires a `handleRequest` method during initialisation\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/server/environments/fetchableEnvironments.ts","lineNumber":22,"sourceCode":"import type { Environment } from '../../environment'\n\nexport interface FetchableDevEnvironmentContext extends DevEnvironmentContext {\n  handleRequest(request: Request): Promise<Response> | Response\n}\n\nexport function createFetchableDevEnvironment(\n  name: string,\n  config: ResolvedConfig,\n  context: FetchableDevEnvironmentContext,\n): FetchableDevEnvironment {\n  if (typeof Request === 'undefined' || typeof Response === 'undefined') {\n    throw new TypeError(\n      'FetchableDevEnvironment requires a global `Request` and `Response` object.',\n    )\n  }\n\n  if (!context.handleRequest) {\n    throw new TypeError(\n      'FetchableDevEnvironment requires a `handleRequest` method during initialisation.',\n    )\n  }\n\n  return new FetchableDevEnvironment(name, config, context)\n}\n\nexport function isFetchableDevEnvironment(\n  environment: Environment,\n): 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,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/server/environments/fetchableEnvironments.ts#L4-L40","documentation":"createFetchableDevEnvironment at fetchableEnvironments.ts:22 requires context.handleRequest to be present, because dispatchFetch delegates every request to it. Omitting it leaves the environment unable to serve anything, so the constructor throws a TypeError at init time.","triggerScenarios":"Calling createFetchableDevEnvironment with a context object that lacks handleRequest; passing a context typed loosely (any) where the function was forgotten; refactoring that renamed handleRequest to onRequest or similar.","commonSituations":"SSR framework integration that forgot to wire the request handler; copy-paste from DevEnvironment examples (which do not need handleRequest) into a Fetchable setup; TypeScript bypassed with as any hiding the missing field.","solutions":["Provide context.handleRequest as a function (request: Request) => Promise<Response> | Response when calling createFetchableDevEnvironment.","Double-check the FetchableDevEnvironmentContext interface — handleRequest is required, not optional.","If you have no request handler yet, use DevEnvironment directly instead of the Fetchable variant."],"exampleFix":"// before\nconst env = createFetchableDevEnvironment('ssr', config, { transport })\n\n// after\nconst env = createFetchableDevEnvironment('ssr', config, {\n  transport,\n  handleRequest: (req) => app.ssrFetch(req),\n})","handlingStrategy":"type-guard","validationCode":"function assertHandlerContext(ctx: { handleRequest?: unknown }) {\n  if (typeof ctx.handleRequest !== 'function') {\n    throw new Error('FetchableDevEnvironment requires context.handleRequest')\n  }\n}","typeGuard":"function hasHandleRequest(ctx: { handleRequest?: unknown }): ctx is { handleRequest: (r: Request) => Promise<Response> | Response } {\n  return typeof ctx.handleRequest === 'function'\n}","tryCatchPattern":null,"preventionTips":["Always pass context.handleRequest when creating a FetchableDevEnvironment.","Let TypeScript guide you: do not widen the context to any.","Use DevEnvironment instead if you have no request handler."],"tags":["environment","fetch-api","config","validation"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}