I am working on a Next.js project with TypeScript and Prisma. When running npm run build, the build fails with the following error:
Type error: Type '{ __tag__: "GET"; __param_position__: "second"; __param_type__: { params: { id: string; }; }; }' does not satisfy the constraint 'ParamCheck<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]
Error Context: File causing issue: route.ts in app/api/projects/[id]. Relevant Code: Here’s the snippet of the GET handler that seems to cause the issue:
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const project = await prisma.project.findUnique({
where: { id: params.id },
});
if (!project) {
return NextResponse.json({ error: "Project not found" }, { status: 404 });
}
return NextResponse.json(project);
} catch (error) {
console.error("Error fetching project:", error);
return NextResponse.json({ error: "Failed to fetch project" }, { status: 500 });
}
}
What I’ve Tried:
Checked tsconfig.json settings (strict mode enabled):
{ "compilerOptions": { "strict": true, "moduleResolution": "node", "skipLibCheck": true } }
Reinstalled node_modules and regenerated Prisma client: **
rm -rf node_modules package-lock.json npm install npx prisma generate
** Project Versions: Next.js: 15.1.2 Prisma: 6.2.1 TypeScript: 5.x
You're getting this error because in Next.js 15, params
is actually a Promise that needs to be awaited. Here is how you can fix this:
export async function GET(
request: Request,
{params}: { params: Promise<{ id: string }> }
) {
const id = await params.id
// rest of your code
}