vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.

Home Page:https://subscription-payments.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DynamicServerError - Dynamic server usage: cookies

rbtrsv opened this issue · comments

DynamicServerError: Dynamic server usage: cookies
at staticGenerationBailout (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:10006:21)
at Object.cookies (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:9896:62)
at NextServerComponentAuthStorageAdapter.getCookie (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/128.js:203:42)
at NextServerComponentAuthStorageAdapter.getItem (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/128.js:571:28)
at getItemAsync (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:3174:33)
at SupabaseAuthClient.__loadSession (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:1457:71)
at SupabaseAuthClient._useSession (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:1439:39)
at SupabaseAuthClient._emitInitialSession (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:1942:27)
at /Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:1932:22
at /Users/robert.radoslav/Temp/last/nextjs-subscription-payments/.next/server/chunks/456.js:1403:36 {
digest: 'DYNAMIC_SERVER_USAGE'
}

Node.js v18.17.1

Build error occurred
Error: Call retries were exceeded
at ChildProcessWorker.initialize (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
at ChildProcessWorker._onExit (/Users/robert.radoslav/Temp/last/nextjs-subscription-payments/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
at ChildProcess.emit (node:events:514:28)
at ChildProcess.emit (node:domain:489:12)
at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
type: 'WorkerError'
}
[ ] - info Generating static pages (6/8)%

This is when I run "npm run build".

I'm also facing the same issue, this issue is same as

  • #223
    I used the solution given
export const dynamic = "force-dynamic"

and it resolves the issue but I'm not sure if thats the correct way

Same here. I had to fix a few different errors before my dev build passed on Vercel. The above fix also worked for me and I fixed the other fairly self explanatory errors on my own. Thanks for the above.

Can the "force-dynamic" be prevented by changing

export const createServerSupabaseClient = cache(() =>
  createServerComponentClient<Database>({ cookies })
);

to

export const createServerSupabaseClient = cache(() => {
  const cookieStore = cookies();
  return createServerComponentClient<Database>({cookies: () => cookieStore});
});

in app/supabase-server.ts?

export const createServerSupabaseClient = cache(() => {
const cookieStore = cookies();
return createServerComponentClient({cookies: () => cookieStore});
});

Thanks @jrhizor it fixed the issue 👍