Next.js Discord

Discord Forum

Getting a Prerender Error during deployment as well as a type error

Answered
Kentos posted this in #help-forum
Open in Discord
The post is too long so it's converted it to a message.txt
Answered by Kentos
Vercel needed env variables added before deployment. Adding those fixed the issue. Thanks so much for your help!! 🙂
View full answer

10 Replies

@Kentos The post is too long so it's converted it to a message.txt
By seeing half of the code, You're not handling any errors, which caused the build process to failed. fixing those errors can be done after you add try catch
Sorry, I'm a little confused on what you mean "By seeing 2 files?"
@Kentos Sorry, I'm a little confused on what you mean "By seeing 2 files?"
My bad, I meant half of the code*
@Anay-208 My bad, I meant half of the code*
Ok, I'll try giving that a go. I'm still confused why the local build isn't running into any errors, but the deployment to vercel is when it runs into those errors? Also I know it's not a standard try catch, but I do have the follwoing throw error.

if (responseBody && responseBody.data && responseBody.data.pageBy) {
return responseBody.data.pageBy;
} else {
throw new Error("Failed to fetch the page");
}
return 500 error to client also
@Anay-208 return 500 error to client also
What do you mean by that?
to send the data to the client that an error occurred
Vercel needed env variables added before deployment. Adding those fixed the issue. Thanks so much for your help!! 🙂
Answer
Donskoy
I had a similar issue, the prebuild step failed because it tried fetching data from our strapi cms during build phase, while the env variables were still unavialable. We ended up disabling the prebuild by modifying the build script:
"build": "next build --experimental-build-mode compile",