#Error with Dynamic content when building project

1 messages · Page 1 of 1 (latest)

sullen shard
#

Hello there! I am encountering the following error in my project when running pnpm build. Please help me understand how to fix this.

My repository is private, so please DM me your email if you're willing to help so I can share my repo with you.

    at staticGenerationBailout (/vercel/path0/.next/server/chunks/37.js:202:21)
    at headers (/vercel/path0/.next/server/chunks/37.js:84:62)
    at getServerSession (/vercel/path0/.next/server/chunks/10.js:9720:41)
    at getAuthSession (/vercel/path0/.next/server/chunks/98.js:38:87)
    at RootLayout (/vercel/path0/.next/server/chunks/119.js:565:51)
    at preloadComponent (/vercel/path0/node_modules/.pnpm/next@13.4.9_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/app-render/preload-component.js:23:22)
    at /vercel/path0/node_modules/.pnpm/next@13.4.9_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/app-render/app-render.js:606:101
    at async createComponentTree (/vercel/path0/node_modules/.pnpm/next@13.4.9_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/app-render/app-render.js:606:29)
    at async /vercel/path0/node_modules/.pnpm/next@13.4.9_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/app-render/app-render.js:810:60 {
  digest: 'DYNAMIC_SERVER_USAGE'
tribal violetBOT
#

Hi @sullen shard. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error message DynamicServerError: Dynamic server usage: headers indicates that you're trying to use server functions like headers in a static export mode. In static export mode, there is no runtime server, so server functions like headers or cookies cannot be used. If you need to use server functions, you cannot use a static export. This is to ensure that local development matches the same behavior as a static export.

Here is the relevant extract from the Next.js documentation:

After enabling the static export output mode, all routes inside app are opted-into the following Route Segment Config (https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config):

export const dynamic = 'error'

With this configuration, your application will produce an error if you try to use server functions like headers (https://nextjs.org/docs/app/api-reference/functions/headers) or cookies (https://nextjs.org/docs/app/api-reference/functions/cookies), since there is no runtime server. This ensures local development matches the same behavior as a static export. If you need to use server functions, you cannot use a static export.

To fix this issue, you need to review your application and remove or replace the usage of server functions in the static export mode. If you need to use server functions, consider using a different mode that supports server functions.

Unfortunately, I can't provide more specific guidance without seeing your code. However, I hope this general advice helps you troubleshoot the issue. If you need more help, consider referring to the Next.js documentation (https://nextjs.org/docs) or seeking help from the Next.js community.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: