Next.js Discord

Discord Forum

Error]: Dynamic server usage: Page couldn't be rendered statically because it used `nextUrl.searchPa

Unanswered
Leafcutting bee posted this in #help-forum
Open in Discord
Leafcutting beeOP
i have executed this code
export const dynamicParams = true;
import { NextRequest, NextResponse } from "next/server";
import { Prisma, PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export const GET = async (req: NextRequest, res: NextResponse) => {
  
  try {
    const pageParam = req.nextUrl.searchParams.get("skip");
    const page = pageParam ? parseInt(pageParam, 10) : 1 ;
    const resultsPerPage = 10;
    const skip = (page - 1) * resultsPerPage;

    const documents = await prisma.learned.findMany({
      orderBy: {
        createdAt: "desc",
      },
      skip: skip || 1 ,
      take: resultsPerPage,
    });

    if (!documents || documents.length === 0) {
      return NextResponse.json({ message: "No data found" }, { status: 404 });
    } else {
      // console.log(allShared);
      return NextResponse.json(documents, { status: 200 });
    }
  } catch (error) {
    console.log(error);
  } finally {
    await prisma.$disconnect();
  }
};

its working fine when use npm run dev, but when i try to deploy on vercel or use build
i will get this error,
what did i do wrong sir

0 Replies