I'm getting this weird bug when running npm run start
Unanswered
Barbary Lion posted this in #help-forum
Barbary LionOP
Everything works in dev mode. When running
It's only when I try to start and log in specifically that I get this error. But absolutely nothing on my code changed for it to start happening (it didn't happen before) and apparently it's an error regarding the headers that Next-Auth tries to access, at least according with my tries to debug it.
Has anyone faced anything similar?
npm run build I get some warnings, but everything still builds.It's only when I try to start and log in specifically that I get this error. But absolutely nothing on my code changed for it to start happening (it didn't happen before) and apparently it's an error regarding the headers that Next-Auth tries to access, at least according with my tries to debug it.
Has anyone faced anything similar?
72 Replies
Barbary LionOP
up
can u show me a screenshot of your nextauth handler?
Barbary LionOP
Yeah, sure
1 sec
is this readable lol
if you open on the browser it should be
And the thing is that it works as normal on the dev server, thats the thing thats getting me
@Barbary Lion is this readable lol
i cant really read it
Barbary LionOP
If you open it on the browser it should let you zoom in and out accordingly @gin
that little button on the bottom left when you open the image
Barbary LionOP
yeah
and i dont think there is anything wrong with the login implementation, because it works okay on dev and it used to work on prod before
i think something happens on the build process that its messing up the requests or smth idk
@Barbary Lion i think something happens on the build process that its messing up the requests or smth idk
does it happen on build proccess?
u need to clarify where it exactly happens so we can narrow down
where and when
Barbary LionOP
it only happens when running the build with
npm run start and at the process of trying to log in @ginSorry for the late response!
so basically ur build process doesnt exit?
Barbary LionOP
it does
u just get error
aha
Barbary LionOP
I get some errors like "this page and whatnot is dynamic because it use headers (even though nothing uses it lol)"
But is still builds, yk?
what if u
place this in your route handler?
export const dynamic = 'force-dynamic'place this in your route handler?
in your dynamic nextauth one
Barbary LionOP
the login is using the pages/ route
wouldnt change anything, i think they are "dynamic" by default, right?
Barbary LionOP
so what would be the equivalent on the pages/ way?
i know
my [...nextAuth] is inside the api route on the pages/ folder
oh?
why?
Barbary LionOP
so the
export const dynamic syntax isnt valid there@gin why?
Barbary LionOP
because we did it way on the beginning of the next 13 version and they still didnt have support for their own api folder
but it works
and all your other codebase is in your app router?
well, time to switch
https://authjs.dev/getting-started/migrating-to-v5
https://authjs.dev/getting-started/migrating-to-v5Barbary LionOP
yeah i thought of doing that and maybe it will work
is it safe for a prod envinroement though?
and still, it says right there that the pages/ is still supported
shouldnt be an issue that im using it on the v4 or v5
if u dont want to migrate, i think its better to correctly follow the docs https://next-auth.js.org/configuration/nextjs
i think you shouldnt have problems when u follow this correctly
if u still get the same error, that means somewhere in your app router a route is pre rendering the nextauth route and somehow something failes
@gin if u still get the same error, that means somewhere in your app router a route is pre rendering the nextauth route and somehow something failes
Barbary LionOP
why do you think that is? are you aware of some bug that looks like that?
i think that cause if it happens on build process and the call stack points to your nextauth route, most of the time its a pre rendering issue
Barbary LionOP
it doesnt happen on build processs though, it happens when im already running the build and try to log in there
but it makes sense that something gets lost on the build, because the error stack trace is pointing to the build (obviously)
@Barbary Lion it doesnt happen on build processs though, it happens when im already running the build and try to log in there
in this case u can debug your auth functions cause something is probably not defined
can u share your codebase so i can reproduce it?
Barbary LionOP
there are some errors on the build, but they are from not succeeding to generate static pages (which shouldnt break anything, right? its just worse in performance)
but the build goes through anyway, the problem is when trying to log in with the build generated
but the build goes through anyway, the problem is when trying to log in with the build generated
@gin can u share your codebase so i can reproduce it?
Barbary LionOP
sorry i cant :/ its from my company, its prod
but thank you a lot for your help, though. I see you're trying
Heres what im going to do: Im going to migrate everything to nextAuth v5 (since it should be the best compatible version with the app/ folder) and try to start the build again
If i get exactly the same error i know its probably not related with nextAuth PER SE
Heres what im going to do: Im going to migrate everything to nextAuth v5 (since it should be the best compatible version with the app/ folder) and try to start the build again
If i get exactly the same error i know its probably not related with nextAuth PER SE
good idea 👍
Barbary LionOP
From there i'll try to solve the build errors on generating the static pages, maybe they influence where the code generated that next auth uses somehow
the fact that it doesnt happen on dev leads me to think its a problem with the build