Open skorfmann opened 1 year ago
I get this too, it looks like it never builds any api route pages, for me anyway!
I've tried adding
export const dynamic = 'force-dynamic'; export const revalidate = 0;
to those pages but it has no effect :(
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?
Same problem here!
Any news here guys?
Check here https://github.com/vercel/nextjs-subscription-payments/issues/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,
Error: DynamicServerError: Dynamic server usage: cookies
at staticGenerationBailout (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/449.js:279:21)
at Object.cookies (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/449.js:171:62)
at NextServerComponentAuthStorageAdapter.getCookie (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/799.js:203:42)
at NextServerComponentAuthStorageAdapter.getItem (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/799.js:571:28)
at /home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/511.js:3078:37
at Generator.next (<anonymous>)
at /home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/511.js:2986:71
at new Promise (<anonymous>)
at __awaiter (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/511.js:2968:12)
at getItemAsync (/home/danielhcarranza/projects/webapps/legalagent/.next/server/chunks/511.js:3077:38) {
digest: 'DYNAMIC_SERVER_USAGE'
}
I fixed it by adding export const revalidate = 0;
to the layout.tsx
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() { 'use server' const supabase = createServerSupabaseClient(); try { const { data: { session } } = await supabase.auth.getSession(); return session; } catch (error) { console.error('Error:', error); return null; } }
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...
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() { 'use server' const supabase = createServerSupabaseClient(); try { const { data: { session } } = await supabase.auth.getSession(); return session; } catch (error) { console.error('Error:', error); return null; } }
Here is the Next JS page that helped me solve:
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
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.
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() { 'use server' const supabase = createServerSupabaseClient(); try { const { data: { session } } = await supabase.auth.getSession(); return session; } catch (error) { console.error('Error:', error); return null; } }
Here is the Next JS page that helped me solve:
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
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.
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.
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
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:
export const dynamic = "force-dynamic"
export const revalidate = 0
insert "use server" on the top of the file (or in the next line after declaration)
To explain that function will run on the server.
See the code behind getSession: https://github.com/supabase/gotrue-js/blob/15c7c8258b2d42d3378be4f7738c728a07523579/src/GoTrueClient.ts#L898
I'm seeing this error https://github.com/vercel/next.js/issues/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?