Next.js Discord

Discord Forum

Heelp!! Error with NextAuth when using Vite as a server and its settings

Unanswered
Saltwater Crocodile posted this in #help-forum
Open in Discord
Saltwater CrocodileOP
Help guys!

Hello everyone, I'm back here with the same error, now with the difference that, when deactivating vite, nextauth works, but I have no idea why!! I didn't want to lose the advantages of using vite, because after I removed it, everything went wrong!!!

I'm about 15 days into this error, and the only thing I've discovered is that it works without vite:
As I've been stuck with this error for a long time, I've tried everything, I've looked for forums, chats, but so far nothing

The error occurs as soon as the first page opens, in this case the login page or any other: error:

logger.js:46 [next-auth][error][CLIENT_FETCH_ERROR]
client_fetch_error Unexpected token '<', "<!DOCTYPE "... is not valid JSON
{error: {…}, url: '/api/auth/session', message: Unexpected token '<', "<!DOCTYPE "... is not valid JSON}
client: true

error: {message: Unexpected token '<', "<!DOCTYPE "... is not valid JSON, stack: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON, name: 'SyntaxError'}
message: "Unexpected token '<', "<!DOCTYPE "... is not valid JSON"
url: "/api/auth/session"


Without vite it works, but I lose all configuration, css (Tailwind), the routes break, among other problems, but NexthAuth really works without vite

I tried to downgrade the nextauth version from ^4.23.1 to 4.22.2, but the error persists

"scripts": {
"devViteShareDevices": "vite --host 0.0.0.0", // does not work (NextAuth)
"devVite": "vite",
"dev": "next dev", // it works (NextAuth)
"build": "next build",
"start": "next start",
"lint": "next lint"
},


https://github.com/vitejs/vite/discussions/14203


Below is a link where I demonstrate the error and operation: video:

https://www.dropbox.com/scl/fi/99c1pr4o546fgg1wnc8zq/ViteNextAuth2.mp4?rlkey=s6ge2e00vtom24eaexwswottz&dl=0

I ask for everyone's help!! Need more information just ask!

Tks

0 Replies