Dynamic Server Error in Next js with Supabase Server Client Component
Answered
Sohel Shekh posted this in #help-forum
I am working on a Next app with Supabase in all the pages that are not "use client" pages, I am getting this error
DynamicServerError: Dynamic server usage: Page couldn't be rendered statically because it used
and the code is this
DynamicServerError: Dynamic server usage: Page couldn't be rendered statically because it used
cookies. See more info here: https://nextjs.org/docs/messages/dynamic-server-errorand the code is this
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import Link from "next/link";
export default async function Home() {
const supabase = createServerComponentClient({ cookies });
const {
data: { user },
} = await supabase.auth.getUser();Answered by Himalayan
I found my issue, I forgot to delete part of the old code from one of the functions and it's working now!
15 Replies
I also tried placing expoer dynamic = "force-dynamic"
But not working
@Sohel Shekh I also tried placing expoer dynamic = "force-dynamic"
Himalayan
I'm also getting this error
did you find any fix for it?
New Guinea Singing Dog
try passing
export const revalidate = 0Also make sure that it's also for your Route Handlers/API (With createRouteHandlerComponent) it also needs force-dynamic
@New Guinea Singing Dog Also make sure that it's also for your Route Handlers/API (With createRouteHandlerComponent) it also needs force-dynamic
New Guinea Singing Dog
thats what kept me up for so long 😆
Himalayan
Revalidate didn't help
New Guinea Singing Dog
were both of these added to layout.tsx?
Himalayan
Do you mean do I connect to supabase multiple times or to multiple different projects?
And yes, both were added to layout.jsx
And yes, both were added to layout.jsx
New Guinea Singing Dog
you know when you go fetch('/api/endpoint') in your component
Are any of those creating any instances of supabase? They wouldn't be covered by layout.jsx
Are any of those creating any instances of supabase? They wouldn't be covered by layout.jsx
Himalayan
got it, yea that wasn't it.
Himalayan
I found my issue, I forgot to delete part of the old code from one of the functions and it's working now!
Answer
New Guinea Singing Dog
Glad you solved it :)
let me know if i chose the wrong message