'authOptions' is not a valid Route export field

Hi everyone,
In the “Preparing to Deploy” tutorial, when we run npm run build , we get the above stated error.

I know Mosh explained the solution to create a separate script for authOptions and then import it in [...nextauth]/route.ts and the error goes away.

Question here:
How does this solve the underlying issue? which is that we can’t export an invalid Route export field. ?

I mean to ask: we still export authOptions as handler in route.ts, as follows:

const handler = NextAuth(authOptions)

export { handler as GET, handler as POST }

So, how does the error go away?

Hi, im getting the same error, did u fix it?

It’s just an export error. As long as it’s not a route file exporting authOptions, the error should not appear. Only functions like GET, POST, etc can be exported from a route file.