跳转到内容

Astro.locals is not serializable

LocalsNotSerializable:在路径 “HREF” 下存储的 Astro.locals 中的信息不可序列化。请确保只存储可序列化的数据。(E03034)

在开发模式下,当用户尝试将不可序列化的内容存储在 locals 中时,会抛出该错误。

例如:

import { defineMiddleware } from "astro/middleware";
export const onRequest = defineMiddleware((context, next) => {
context.locals = {
foo() {
alert("Hello world!")
}
};
return next();
});
贡献 社区 赞助