-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamicServerError: Dynamic server usage: cookies when trying to deploy #201
Comments
Same error on my side (( |
Same error for me as well when using cookies in the latest supabase auth helpers. No issues with previous Nextjs version (pre 13.4) and older supabase auth helpers. |
Same problem here! Any news here guys? |
Check here #202 there are some workarounds |
Same error, has anyone figured it out yet? I tried all the steps with the latest versions but no success,
|
I fixed it by adding |
I don't like the export const revalidate =0; solution, I don't want my entire app to build and operate like that. I fixed it by add "use server" to the supabase-server.ts functions (getSession, getUserDetails, getSubscription, getActiveProductsWithPrices). The createServerSupabaseClient was giving me issues with the {cookies} it passes via server component. Here's what a function looked like: export async function getSession() { Here is the Next JS page that helped me solve: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions |
Im still getting this I tried all of these fixes, I cannot for my life figure out why |
Me too :( |
Anyone fix it? |
So very sad. The app was working for me, then I saw that a build failed. I went and reverted to the last successful build. From then on none of the builds suceded. Any news? |
removing the supabase cli fixed it for me. |
Dear God... |
This fixed it for me, thanks! |
I've tried adding 'use server' to every function supabase is related to, and still nothing works. |
This #223 fixed the error for me. |
but if I use this, I won't be able to get any auth token that is on cookies no? |
I discovered that if the cookie is called inside a try-catch it will generate this error. Solutions: put the calling of the cookie (and headers) outside try-catch. |
no one is calling the cookie in try catch. it's called from server components |
I think this error kinda makes sense? If there is a page (or anything) that is using something that dynamically changes such as a cookie, even if that cookie is nested inside a server action then it can't render as a static resource. In my case, the app still deploys every time despite the 'errors' - this may not be the same experience that other users are having however. I actually think that this is meant to be a warning rather than an error and should still allow the posting of the app build. Nextjs / Nextjs on Vercel might have a failsafe were if it can't render it statically, it'll shift it to dynamic? Try doing something like this with your supabase server/serveraction clients. const cookieStore = cookies();
const supabase = createWhateverTypeClient<Database>({ cookies: () => cookieStore }); I know the supabase docs especially for serverActionClient use ({ cookies }) but this could be causing the issue. Unsure how long this has been up in the nextjs docs but here is a reference to their help doc to resolve the 'error' : https://nextjs.org/docs/messages/dynamic-server-error Due to the app deploying and functioning I've put this in the 'deal with later' basket but hopefully these solutions might get people closer to a resolution. |
Sorry for not explaining it before, but in the background, when you use getSession of supabase, it will try to get cookies. And, if it is inside a try-catch, as in the example of BenLyddane, you will get an error. The way to fix that is doing as DoIevenLift: put cookies outside any other function or conditional. When you declare cookies in this way, the build will understand that it is not a static content. Other important thing is, if the cookie is called inside a server component, but wrapped in another function, you needs to use one of those options:
To explain that function will run on the server. See the code behind getSession: |
This is what I got from Copilot, when I had entered the error response: **Possible Solutions export const dynamic = 'force-dynamic'; import { cookies } from 'next/headers'; if (typeof window !== 'undefined') { |
I'm seeing this error vercel/next.js#49373 when trying to deploy the example via Vercel.
Here's an excerpt from the build logs.
tried this with
next@13.4.5
as wellAny way to fix this?
The text was updated successfully, but these errors were encountered: