Next.js Discord

Discord Forum

Error: Property 'nextUrl' does not exist on type 'Request'

Answered
Waterman posted this in #help-forum
Open in Discord
I have a funciton,writen below, and I use that funciton to fetch data from two different client components, is my setup or correct or should I make another route.ts file somewhere to not have two get request in the same GET function?

But my real question, why do I get an error when using nextUrl?

Error: linked as picture

I appreciate all help, thanks 🙂

export const GET = async (req: Request, res: Response) => {
  const { method } = req;
  const queryId = req.nextUrl.searchParams.get("id");
  await mongooseConnect();
  if (method === "GET") {
    if (queryId) {
      return NextResponse.json(await BasProdukt.findOne({ _id: queryId }));
    }
  }
  if (method === "GET") {
    return NextResponse.json(await BasProdukt.find());
  }
};
Answered by Giant panda
Because NextRequest is a type and not an object
View full answer

4 Replies

Giant panda
Use the NextRequest type for that since it's an extension to the standard Request object
i still get the same error though,
Giant panda
Because NextRequest is a type and not an object
Answer
thanks alot, now I understand