Next.js Discord

Discord Forum

Why is Next.js considering this route as static?

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
Hey guys! I'm pretty new here, trying to figure out a routing issue. I've created a route where I'm calling the database right within the component itself. There's no authentication required for this route — anyone can access it. The objective is to allow anyone to refresh the page and see updated data if there is any.

But here's where the issue comes in. Every time I do a npm run build, Next.js seems to think that this route is static. What could I possibly be doing wrong?

export default async function PostPage() {
  const posts = await db.post.findMany({
    select: {
      id: true,
      title: true,
      published: true,
      createdAt: true,
    },
    orderBy: {
      updatedAt: "desc",
    },
  });

  // rest of code

}


Route (app)                                Size     First Load JS
┌ ○ /                                      4.93 kB        82.5 kB
├ ○ /post                                  175 B          83.6 kB
â”” â—‹ /login                                 14.5 kB         100 kB
+ First Load JS shared by all              77.6 kB
  ├ chunks/769-23359a1c37d5fe30.js         25.1 kB
  ├ chunks/bce60fc1-a10169790ee3ceae.js    50.5 kB
  ├ chunks/main-app-4019368769fe2e7b.js    216 B
  â”” chunks/webpack-b675f68cc928422b.js     1.74 kB

Route (pages)                              Size     First Load JS
┌ ○ /404                                   182 B          75.5 kB
└ λ /api/auth/[...nextauth]                0 B            75.4 kB
+ First Load JS shared by all              75.4 kB
  ├ chunks/framework-8883d1e9be70c3da.js   45 kB
  ├ chunks/main-969df15ffc4ad18f.js        28.4 kB
  ├ chunks/pages/_app-998b8fceeadee23e.js  195 B
  â”” chunks/webpack-b675f68cc928422b.js     1.74 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
â—‹  (Static)  automatically rendered as static HTML (uses no initial props)

5 Replies

@Asiatic Lion Hey guys! I'm pretty new here, trying to figure out a routing issue. I've created a route where I'm calling the database right within the component itself. There's no authentication required for this route — anyone can access it. The objective is to allow anyone to refresh the page and see updated data if there is any. But here's where the issue comes in. Every time I do a npm run build, Next.js seems to think that this route is static. What could I possibly be doing wrong? export default async function PostPage() { const posts = await db.post.findMany({ select: { id: true, title: true, published: true, createdAt: true, }, orderBy: { updatedAt: "desc", }, }); // rest of code } Route (app) Size First Load JS ┌ ○ / 4.93 kB 82.5 kB ├ ○ /post 175 B 83.6 kB └ ○ /login 14.5 kB 100 kB + First Load JS shared by all 77.6 kB ├ chunks/769-23359a1c37d5fe30.js 25.1 kB ├ chunks/bce60fc1-a10169790ee3ceae.js 50.5 kB ├ chunks/main-app-4019368769fe2e7b.js 216 B └ chunks/webpack-b675f68cc928422b.js 1.74 kB Route (pages) Size First Load JS ┌ ○ /404 182 B 75.5 kB └ λ /api/auth/[...nextauth] 0 B 75.4 kB + First Load JS shared by all 75.4 kB ├ chunks/framework-8883d1e9be70c3da.js 45 kB ├ chunks/main-969df15ffc4ad18f.js 28.4 kB ├ chunks/pages/_app-998b8fceeadee23e.js 195 B └ chunks/webpack-b675f68cc928422b.js 1.74 kB λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps) ○ (Static) automatically rendered as static HTML (uses no initial props)
You dont use any dynamic functions so it is static by default
You can force dynamic rendering by export const dynamic = force-dynamic
Asiatic LionOP
Thanks @joulev, that worked!
Grass carp
Didn't work for me :/ Maybe I'm missing something?
Grass carp
Finally found out, I had an api folder with some routes that also needed to be marked as dynamic with export const revalidate = 0;