On this page

RequestEventUnavailableError

Trace RequestEvent resolution outside a request-provided effect context.

What this error means and what can trigger it

RequestEventUnavailableError means effect tried to resolve SER's RequestEvent context reference while no request-specific service was present.

This often happens when code yields the reference during module initialization, manually runs a request-dependent effect without its handler context, or detaches work from the effect that received the current event. Startup and process-wide runtime scopes cannot supply one either because no request owns those scopes.

Valid remote execution paths provide the service immediately before running handler work. Ordinary handlers do so in server/effects.ts, live handlers do so in their Stream execution path, and the Handler wrapper provides it around the user handler effect.

Exactly where it triggers

export const RequestEvent = Context.Reference<RequestEvent>("@ser/RequestEvent", {
	defaultValue: () => {
		throw new RequestEventUnavailableError();
	},
});

The default function executes only when an effect cannot find a provided value in the current context. It throws synchronously during context resolution, which occurs while the surrounding effect is running.

Providing sites include modules/svelte-effect-runtime/src/server/handler.ts L50 @ C34, modules/svelte-effect-runtime/src/server/effects.ts L91 @ C33, and modules/svelte-effect-runtime/src/server/effects.ts L165 @ C33. For reference, the class itself is declared at modules/svelte-effect-runtime/src/errors.ts L361 @ C14.

Why this is the case

A request event cannot safely be global. The server may execute several requests concurrently, each with its own cookies, locals, URL, platform values, and lifecycle. Falling back to shared state could therefore expose one request's data to another.

The context reference makes request ownership part of effect execution. Work retains access only while it runs inside the context provided for that specific handler invocation.