next.jsbuildapp-routernext.js15

Error building the aplication (Linting and checkin validity of types .Failed to compile)


I have created an Next.js Aplication, it doesn't present any error on next dev nor in next lint but when i run the next build, the error occurs:

.next/types/app/api/queries/[id]/route.ts:49:7
<RouteContext>'.
  The types of '__param_type__.params' are incompatible between these types.
    Type '{ id: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]

  47 |     Diff<
  48 |       ParamCheck<RouteContext>,
> 49 |       {
     |       ^
  50 |         __tag__: 'GET'
  51 |         __param_position__: 'second'
  52 |         __param_type__: SecondArg<MaybeField<TEntry, 'GET'>>

I cannot build the aplication because of the error

code where the error supposedly occurs

import { fetchImagesById, fetchPdfById, fetchReferenciasById } from "@/lib/db";
import { NextRequest, NextResponse } from "next/server";

export async function GET(
  req: NextRequest,
  { params }: { params: { id: string } },
) {
  const { id } = await params;

  let referencias: any[];
  let fotos: any[];
  let pdf: any[];

  try {
    if (id) {
      // Fetch referencias, fotos, pdf
      referencias = await fetchReferenciasById(id);
      pdf = await fetchPdfById(id);
      fotos = await fetchImagesById(id);

      const fotosUpdated = fotos.map((item) => ({
        foto_1: item.foto_1
          ? `data:image/png;base64,${Buffer.from(item.foto_1).toString("base64")}`
          : "/foto_placeholder.png",
        foto_2: item.foto_2
          ? `data:image/png;base64,${Buffer.from(item.foto_2).toString("base64")}`
          : "/foto_placeholder.png",
        foto_3: item.foto_3
          ? `data:image/png;base64,${Buffer.from(item.foto_3).toString("base64")}`
          : "/foto_placeholder.png",
        foto_4: item.foto_4
          ? `data:image/png;base64,${Buffer.from(item.foto_4).toString("base64")}`
          : "/foto_placeholder.png",
        foto_5: item.foto_5
          ? `data:image/png;base64,${Buffer.from(item.foto_5).toString("base64")}`
          : "/foto_placeholder.png",
        foto_6: item.foto_6
          ? `data:image/png;base64,${Buffer.from(item.foto_6).toString("base64")}`
          : "/foto_placeholder.png",
      }));

      const pdfUpdated = pdf.map((item) => ({
        medidas_montagem: item.medidas_montagem
          ? `data:application/pdf;base64,${Buffer.from(item.medidas_montagem).toString("base64")}`
          : "-",
      }));

      const unifiedResult = {
        referencias,
        pdfUpdated,
        fotosUpdated,
      };
      return NextResponse.json(unifiedResult);
    }

    return NextResponse.json(
      { message: "Invalid query parameters." },
      { status: 400 },
    );
  } catch (error) {
    console.error(error);
    return NextResponse.json({ message: "Server error." }, { status: 500 });
  }
}

the builded code that presents the error

checkFields<
    Diff<
      ParamCheck<RouteContext>,
      {
        __tag__: 'GET'
        __param_position__: 'second'
        __param_type__: SecondArg<MaybeField<TEntry, 'GET'>>
      },
      'GET'
    >
  >()

I already try removing the 'await' from `const { id } = await params;`, tried to remove the type and leaving with 'any', tried to add more parameters, but anything seems to work and the aplication doesn't build

I already update all dependencies to the latest version

I'm using Next.js 15.0.2 and App-router


Solution

  • The error you're getting is because you've defined the params object as a plain JS object with an id of string, but then you're treating it as a promise by awaiting it.

    What you want is a params which is a Promise of that object, instead. Per the documentation (https://nextjs.org/docs/app/building-your-application/routing/route-handlers), something like this:

    export async function GET(
      request: Request,
      { params }: { params: Promise<{ id: string }> }
    ) {
      const id = (await params).id
    }