我在Next.js 13中有这个函数:
async function createTodo(data: FormData) {
"use server";
const title = data.get("title")?.valueOf();
if (typeof title !== "string" || title.length === 0) {
throw new Error("Invalid title");
}
await prisma.todo.create({ data: { title: title, complete: false } });
redirect("/");
}
字符串
一切工作正常,直到我放置**重定向(“/”);**显示以下错误:
prisma:query SELECT 1
prisma:query BEGIN
prisma:query INSERT INTO `main`.`Todo` (`id`, `title`, `complete`, `cleatedAt`, `updatedAt`) VALUES (?,?,?,?,?) RETURNING `id` AS `id`
prisma:query SELECT `main`.`Todo`.`id`, `main`.`Todo`.`title`, `main`.`Todo`.`complete`, `main`.`Todo`.`cleatedAt`, `main`.`Todo`.`updatedAt` FROM `main`.`Todo` WHERE `main`.`Todo`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
failed to get redirect response TypeError: fetch failed
at Object.fetch (/home/jorge/next-13-todo-list/node_modules/next/dist/compiled/undici/index.js:1:26669) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at write (/home/jorge/next-13-todo-list/node_modules/next/dist/compiled/undici/index.js:1:67105)
at _resume (/home/jorge/next-13-todo-list/node_modules/next/dist/compiled/undici/index.js:1:66726)
at resume (/home/jorge/next-13-todo-list/node_modules/next/dist/compiled/undici/index.js:1:65413)
at connect (/home/jorge/next-13-todo-list/node_modules/next/dist/compiled/undici/index.js:1:65301) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
型
你在干什么?尽管服务器控制台中显示错误,但应用程序仍处于活动状态并正常工作。但是,当返回到/路由时,结果没有刷新,有什么建议吗?.我该如何修复它?
1条答案
按热度按时间qhhrdooz1#
是否在nextjsConfig上启用了服务器操作?
exports = { experimental:{ serverActions:},int n;