Next.js Discord

Discord Forum

Can't use revalidatePath in route handler

Unanswered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
When i try to use revalidatePath in a route handler I get the error:
[Error: Invariant: static generation store missing in revalidateTag

But it works when calling revalidatePath from a server action. How do i fix this? or is this a bug right now.

1 Reply

Holland Lop
revalidatePath can only be used server-side. I also had a lot of trouble working my way through the same error, but just managed to get the following code to work:

"use server"

export async function myPostFunction(args) {
  const response = await ... //API logic
  await revalidateData();

  return response.toString()
}

async function revalidateData() {
    try {revalidatePath("/", "layout");}
    catch (error) {console.log("revalidateData error", error)}
}