honojs/hono · error · Error
This context has no FetchEvent
Error message
This context has no FetchEvent
What it means
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.
Source
Thrown at src/context.ts:381
/**
* `.req` is the instance of {@link HonoRequest}.
*/
get req(): HonoRequest<P, I['out']> {
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult)
return this.#req
}
/**
* @see {@link https://hono.dev/docs/api/context#event}
* The FetchEvent associated with the current request.
*
* @throws Will throw an error if the context does not have a FetchEvent.
*/
get event(): FetchEventLike {
if (this.#executionCtx && 'respondWith' in this.#executionCtx) {
return this.#executionCtx
} else {
throw Error('This context has no FetchEvent')
}
}
/**
* @see {@link https://hono.dev/docs/api/context#executionctx}
* The ExecutionContext associated with the current request.
*
* @throws Will throw an error if the context does not have an ExecutionContext.
*/
get executionCtx(): ExecutionContext {
if (this.#executionCtx) {
return this.#executionCtx as ExecutionContext
} else {
throw Error('This context has no ExecutionContext')
}
}
/**View on GitHub (pinned to e2740d5a1b)
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
Example fix
// before
const event = c.event // throws: This context has no FetchEvent
// after
const event = 'respondWith' in c.executionCtx ? c.event : undefined
if (event) {
event.waitUntil?.(task) // or respondWith
} else {
c.executionCtx.waitUntil(task)
} Defensive patterns
Strategy: type-guard
Validate before calling
const hasFetchEvent = (c: Context) => {
try {
return 'respondWith' in c.event
} catch {
return false
}
} Type guard
const hasFetchEvent = (c: Context): boolean => {
try {
return 'respondWith' in c.event
} catch {
return false
}
} Try / catch
try {
const event = c.event
event.respondWith(response)
} catch (e) {
// No FetchEvent (e.g. Node.js runtime) — fall back to returning the response
return response
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- This context has no ExecutionContext
- Failed to upgrade WebSocket
- env has to include the 2nd argument of fetch.
- Context is not finalized. Did you forget to return a Respons
- Invalid JSX tag name: ${tag}
AI-assisted analysis of honojs/hono@e2740d5a1b (2026-08-28).
Data as JSON: /api/errors/1ed0366fcd56c1e7.
Report an issue: GitHub.