My NextJS 13 app isn’t building and is returning a type error but it is completely working on development environment
the type error is shown in this file
import NextAuth, { AuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google"
export const authOptions: AuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_ID as string,
clientSecret: process.env.GOOGLE_SECRET as string,
}),
],
}
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST}
the file path is app/api/auth/[…nextauth]/route.ts
This is the error message shown in the console ⬇️
.next/types/app/api/auth/[...nextauth]/route.ts:8:13
Type error: Type 'OmitWithTag<typeof import("D:/4 - Coding/Training/NextAuth/next-auth-new/app/api/auth/[...nextauth]/route"), "config" | "generateStaticParams" | "revalidate" | "dynamic" | "dynamicParams" | ... 9 more ... | "PATCH", "">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'authOptions' is incompatible with index signature.
Type 'AuthOptions' is not assignable to type 'never'.
6 |
7 | // Check that the entry is a valid entry
> 8 | checkFields<Diff<{
| ^
9 | GET?: Function
10 | HEAD?: Function
11 | OPTIONS?: Function
- info Linting and checking validity of types ...
I don’t know where to start since I’m new to the NextJs front ,
tried to google the error but it isn’t returning any relevant answers, bard AI is no help also
2
Answers
I was building an app with NextAuth recently and as I recall they still suggest you using ‘pages’ folder to handle all api requests. So you can try to:
and import them in your route to consume:
Alternatively, you can configure your Next project to forget about TS errros when building as noted here: link
Cheers!
i think the problem is your imports try this :
so that mean change
AuthOption
toNextAuthOptions
andimport NextAuth from "next-auth/next";