{"record":{"id":"1ed0366fcd56c1e7","repo":"honojs/hono","slug":"this-context-has-no-fetchevent","errorCode":null,"errorMessage":"This context has no FetchEvent","messagePattern":"This context has no FetchEvent","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/context.ts","lineNumber":381,"sourceCode":"  /**\n   * `.req` is the instance of {@link HonoRequest}.\n   */\n  get req(): HonoRequest<P, I['out']> {\n    this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult)\n    return this.#req\n  }\n\n  /**\n   * @see {@link https://hono.dev/docs/api/context#event}\n   * The FetchEvent associated with the current request.\n   *\n   * @throws Will throw an error if the context does not have a FetchEvent.\n   */\n  get event(): FetchEventLike {\n    if (this.#executionCtx && 'respondWith' in this.#executionCtx) {\n      return this.#executionCtx\n    } else {\n      throw Error('This context has no FetchEvent')\n    }\n  }\n\n  /**\n   * @see {@link https://hono.dev/docs/api/context#executionctx}\n   * The ExecutionContext associated with the current request.\n   *\n   * @throws Will throw an error if the context does not have an ExecutionContext.\n   */\n  get executionCtx(): ExecutionContext {\n    if (this.#executionCtx) {\n      return this.#executionCtx as ExecutionContext\n    } else {\n      throw Error('This context has no ExecutionContext')\n    }\n  }\n\n  /**","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/honojs/hono/blob/e2740d5a1bd0b4254e517e3af8b60789284bc7bd/src/context.ts#L363-L399","documentation":"Hono's Context.event getter throws when the current request has no FetchEvent available. In Cloudflare Workers and similar runtimes, Hono captures the event/execution context passed to fetch(request, env, ctx); if the app was constructed or invoked without that context (or #executionCtx only holds ExecutionContext), accessing c.event fails because there is genuinely no FetchEvent to return.","triggerScenarios":"Calling c.event inside a handler when the app was served without a FetchEvent — e.g. running under Node.js via @hono/node-server (which passes no FetchEvent), using hc test clients, or when Hono was initialized without passing executionCtx. Also when #executionCtx exists but is an ExecutionContext without respondWith.","commonSituations":"Porting a Cloudflare Workers app to Node.js/adjust adapters; writing unit tests with app.request() (testRequest) which supplies no FetchEvent; calling c.event in web-standard environments where only ExecutionContext exists.","solutions":["Use c.executionCtx instead if you only need ExecutionContext (waitUntil, passThroughOnException) — it works whenever any execution context is present","Guard with 'respondWith' in c.executionCtx or wrap in try/catch before using c.event","On Cloudflare Workers, make sure you export fetch(request, env, ctx) and pass ctx so Hono receives the event/execution context","In tests, use app.request(..., env, executionCtx) or mock an object with respondWith"],"exampleFix":"// before\nconst event = c.event // throws: This context has no FetchEvent\n\n// after\nconst event = 'respondWith' in c.executionCtx ? c.event : undefined\nif (event) {\n  event.waitUntil?.(task) // or respondWith\n} else {\n  c.executionCtx.waitUntil(task)\n}","handlingStrategy":"type-guard","validationCode":"const hasFetchEvent = (c: Context) => {\n  try {\n    return 'respondWith' in c.event\n  } catch {\n    return false\n  }\n}","typeGuard":"const hasFetchEvent = (c: Context): boolean => {\n  try {\n    return 'respondWith' in c.event\n  } catch {\n    return false\n  }\n}","tryCatchPattern":"try {\n  const event = c.event\n  event.respondWith(response)\n} catch (e) {\n  // No FetchEvent (e.g. Node.js runtime) — fall back to returning the response\n  return response\n}","preventionTips":["Prefer c.executionCtx for waitUntil; it works in more runtimes","Pass the ctx argument through when exporting fetch handlers on Workers","Supply stub contexts in tests via app.request(req, env, stubCtx)"],"tags":["hono","fetchevent","cloudflare-workers","context","runtime"],"backgroundTag":"missing-fetch-event","analyzedSha":"e2740d5a1bd0b4254e517e3af8b60789284bc7bd","analyzedAt":"2026-08-28T10:18:08.750Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}