Back to Withastro

Value assigned to locals is not accepted.

src/content/docs/en/reference/errors/locals-not-an-object.mdx

latest493 B
Original Source

import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />

LocalsNotAnObject: locals can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.

What went wrong?

Thrown when locals is overwritten with something that is not an object

For example:

ts
import {defineMiddleware} from "astro:middleware";
export const onRequest = defineMiddleware((context, next) => {
  context.locals = 1541;
  return next();
});