invalid "DELETE" export when building
Unanswered
Bee posted this in #help-forum
BeeOP
export async function DELETE(
req: Request,
context: { params: { [key: string]: string | string[] } }
) {
const session = await getServerSession(authOptions)
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
Errored when building
app/api/notes/[id]/route.ts
Type error: Route "app/api/notes/[id]/route.ts" has an invalid "DELETE" export:
Type "{ params: { id: string; }; }" is not a valid type for the function's second argument.
Things i tried so far:
1. Make it a promis
export async function DELETE(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> }
): Promise<NextResponse> {
const session = await getServerSession(authOptions)
Still does not work
7 Replies
Asian black bear
Still does not workWhat's the exact error message you get when you use your promise-based signature?
@Asian black bear > Still does not work
What's the exact error message you get when you use your promise-based signature?
BeeOP
> research-team-webui@0.1.0 build /Users/yue/school/research-team-webui
> next build
▲ Next.js 15.1.7
- Environments: .env
Creating an optimized production build ...
✓ Compiled successfully
Linting and checking validity of types .Failed to compile.
app/api/notes/[id]/route.ts
Type error: Route "app/api/notes/[id]/route.ts" has an invalid "DELETE" export:
Type "{ params: { id: string; }; }" is not a valid type for the function's second argument.
Next.js build worker exited with code: 1 and signal: null
ELIFECYCLE Command failed with exit code 1.
Asian black bear
It clearly shows that it's not picking up on you adding the
Promise
.It has to be
{ params }: { params: Promise<{ id: string }> }
.im stupid, sorry