Next js 15 cookie build error
Unanswered
Silver Fox posted this in #help-forum
Silver FoxOP
hello guys i have one question please regarding next js 15 cookie
setting the cookie was working well but on development it gave an error that says like Route / couldn't be rendered statically because it used cookies.
the form is client and on that form i used server action and on that server action i used cookie setting and getting mechanism.
it was working well on development but on build i gave me an error.
even i've tried to do it in api route but that doesn't set it i don't know why
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const { uid } = await request.json();
const cookieStore = await cookies();
cookieStore.set("cookieName", uid);
return NextResponse.json({ success: true });
}
this is the code that i used to fix
setting the cookie was working well but on development it gave an error that says like Route / couldn't be rendered statically because it used cookies.
the form is client and on that form i used server action and on that server action i used cookie setting and getting mechanism.
it was working well on development but on build i gave me an error.
even i've tried to do it in api route but that doesn't set it i don't know why
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const { uid } = await request.json();
const cookieStore = await cookies();
cookieStore.set("cookieName", uid);
return NextResponse.json({ success: true });
}
this is the code that i used to fix