vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
5.83k stars 1.19k forks source link

DynamicServerError - Dynamic server usage: cookies #245

Closed rbtrsv closed 9 months ago

rbtrsv commented 10 months ago

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)%

rbtrsv commented 10 months ago

This is when I run "npm run build".

Shivansh-yadav13 commented 10 months ago

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

export const dynamic = "force-dynamic"

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

g-hamilton commented 10 months ago

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.

jrhizor commented 9 months ago

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?

Shivansh-yadav13 commented 9 months ago

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

Thanks @jrhizor it fixed the issue 👍