Next.js Discord

Discord Forum

Type error

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I’m running into an issue with my Next.js code. When I try to use the handleError function, I’m getting the following error:

Type '(error: unknown) => Promise<Response>' is not assignable to type 'never'


Code route.ts
import { handlers } from '@/auth';

export const { GET, POST } = handlers;

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function handleError(error: unknown) {
  console.error('Auth route error:', error);
  return new Response('Internal Server Error', { status: 500 });
}

From what I understand, the handleError function is being used somewhere, but the type is causing a conflict. Does anyone know why this is happening and how I can fix it?
Answered by joulev
You can only export certain things from route.ts files and handleError is not one of them. So you have to move that function to another file.
View full answer

2 Replies