Skip to content
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

Trying to deploy to vercel #7

Open
javierLaris35 opened this issue Aug 1, 2024 · 1 comment
Open

Trying to deploy to vercel #7

javierLaris35 opened this issue Aug 1, 2024 · 1 comment

Comments

@javierLaris35
Copy link

When I tryed to deploy the code to vercel I got this error:

Generating static pages (1/9) [== ]Error fetching session: n [Error]: Dynamic server usage: Route / couldn't be rendered statically because it used headers. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
at l (C:\Codes\tapiceria\tapiceria-hk.next\server\chunks\948.js:1:37247)
at d (C:\Codes\tapiceria\tapiceria-hk.next\server\app(lobby)\page.js:96:2565)
at s (C:\Codes\tapiceria\tapiceria-hk.next\server\app(lobby)\page.js:95:20300)
at m (C:\Codes\tapiceria\tapiceria-hk.next\server\app(lobby)\page.js:110:85375)
at g (C:\Codes\tapiceria\tapiceria-hk.next\server\app(lobby)\page.js:110:85487)
at eh (C:\Codes\tapiceria\tapiceria-hk\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:12:134786)
at e (C:\Codes\tapiceria\tapiceria-hk\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:12:137671)
at ek (C:\Codes\tapiceria\tapiceria-hk\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:12:138145)
at Array.toJSON (C:\Codes\tapiceria\tapiceria-hk\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:12:135755)
at stringify () {
description: "Route / couldn't be rendered statically because it used headers. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
digest: 'DYNAMIC_SERVER_USAGE'

@Jonhvmp
Copy link

Jonhvmp commented Jan 9, 2025

This error occurs because, by default, Next.js (from version 13, with App Router) tries to generate static routes (SSG). However, your "/" route is using some resource that requires dynamic rendering on the server (e.g.: fetching a session with next-auth, reading cookies, calling a database, etc.). When this occurs, Next.js reports “Dynamic server usage” and cannot create the page statically at build time.

Use this code in page.tsx:

export const dynamic = 'force-dynamic';

// Your code that gets the session...
import { getServerSession } from 'next-auth';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants