Next.js Discord

Discord Forum

page refresh throws 500 on next js 12

Unanswered
Kawakawa posted this in #help-forum
Open in Discord
KawakawaOP
I am getting 500 on page refresh for a route at (/blog/:id) after prod deployement. Locally everything works fine. I am using Nextjs 12.

PLease Help!

20 Replies

is there a reason you aren't using v13 (the latest)?
KawakawaOP
We are actually a startup, and v12 is working fine so far.
Also, v13 has some learning curve to it and the team is not yet comfortable
aer you talking about app dir... as you can continue to use pages dir...
KawakawaOP
Btw, the issue has been fixed as follows:
"Removed getIntitialProps, which gets called on on server and client only during navigation and on refresh, only on server-side.
This might've caused props to be null -> Which was giving error."
@riský got any idea about why the above solution fixed it..?
what did your getIntitialProps contain?
KawakawaOP
I am sry I didn't get you..
U need the fucntion definition..?
yeah like what was the function code
KawakawaOP
okk wait let me get that for u
KawakawaOP
hey i am really sry, will need some time to get the code .I dont have access to the repo and the developer is busy...
KawakawaOP
@riský heres the code:

BlogDetail.getInitialProps = async (ctx) => {
const { asPath } = ctx;
let pathArr = asPath?.split("/");
let id = pathArr[pathArr?.length - 1];
let params = { slug: id };
const res = await axios.get(https://cms-api.company.com/api/v1/article/, {
params,
});
return { heading: res?.data?.data[0]?.heading, bannerImage: res?.data?.data[0]?.bannerImage };
};
can i ask why your not doing export const getInitialProps = = async (ctx) => { edit: that is how you do it
if you check the deployment logs on vercel (im guessing thats where its hosted), do you get any more info on what the error could be
as this code doesn't look like it would cause an error...
KawakawaOP
Noo.. I dont have access 😅
This doc says its a legacy api and bunch of other stuff abt how it works ...maybe thts the issue
https://nextjs.org/docs/pages/api-reference/functions/get-initial-props
well nextjs 12 is legacy in its-self
i don't know much about v12 esp pages dir, sorry
KawakawaOP
No worries !! Thank you so much for helping out!