withastro/astro · error · AstroError

ActionCalledFromServerError

ActionCalledFromServerError

Error message

Action called from a server-rendered page or endpoint without using `Astro.callAction()`. This wrapper must be used to call actions from server code.

What it means

The server-side actions proxy (createActionsProxy in the server entrypoint) retrieves the rendering Pipeline from the calling context via Reflect.get(context, pipelineSymbol). If that context is not a real Astro.callAction()-provided ActionAPIContext, pipeline is undefined and AstroError ActionCalledFromServerError is thrown. Server action calls must go through Astro.callAction().

Source

Thrown at packages/astro/src/actions/runtime/entrypoints/server.ts:31

	ActionClient,
	ActionErrorCode,
	ActionInputSchema,
	ActionReturnType,
	SafeResult,
} from '../types.js';

export const getActionPath = createGetActionPath({
	baseUrl: import.meta.env.BASE_URL,
	shouldAppendTrailingSlash,
});

export const actions = createActionsProxy({
	handleAction: async (param, path, context) => {
		const pipeline: Pipeline | undefined = context
			? Reflect.get(context, pipelineSymbol)
			: undefined;
		if (!pipeline) {
			throw new AstroError(ActionCalledFromServerError);
		}
		const action = await pipeline.getAction(path);
		if (!action) throw new Error(`Action not found: ${path}`);
		return action.bind(context)(param);
	},
});

View on GitHub (pinned to d081033d5f)

Solutions

  1. Wrap the call: const result = await Astro.callAction(actions.myAction, input);
  2. Ensure the page/endpoint is server-rendered and that Astro/APIContext is in scope.
  3. For browser calls, use the client actions proxy, not the server entrypoint.

Example fix

// before - src/pages/api/do.astro (frontmatter)
const result = await actions.myAction(input);
// after
const result = await Astro.callAction(actions.myAction, input);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure server calls always go through Astro.callAction by wrapping the actions object.
function callOnServer(astro: { callAction: Function }, actions: Record<string, Function>) {
  return new Proxy(actions, {
    get: (_t, name) => (input: unknown) => astro.callAction(actions[name as string], input),
  });
}

Prevention

When it happens

Trigger: Calling actions.myAction(input) directly inside an Astro frontmatter, an API endpoint, or middleware without wrapping it in Astro.callAction(); or invoking the server entrypoint's proxy from outside a request where no pipeline is attached.

Common situations: SSR page or endpoint that calls an action synchronously like a normal function; calling an action from onRequest middleware; refactoring client calls onto the server without switching to Astro.callAction().

Related errors


AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12). Data as JSON: /api/errors/75dc6c2ed1f4be54. Report an issue: GitHub.