Next.js Discord

Discord Forum

GetStaticProps failed to fetch build for prod

Unanswered
ItetsuLaTable posted this in #help-forum
Open in Discord
Hello, I have an issue with getStaticProps while building my app for productions.
This app is hosted in Hostinger VPS.

When I run "npx next build" I got this issue for all of my pages "TypeError: fetch failed cause connect ECONNREFUSED" and I dunno why

21 Replies

Giant panda
Are you attempting to fetch your own API endpoints during build? If so, don't, because that not going to work if you are trying to fetch data from the app your currently trying to build. If that's not the case you need to share way more details like relevant snippets where this error is happening etc.
Well I'm trying to fetch data from my own api
I don't want to do client side rendering so how can I do ?
Giant panda
Instead of fetching your API during build time you just call the logic that you endpoint would otherwise do directly
I will test that
I got an issue as well
here is the code
export async function getServerSideProps() {

    const response = await fetch(`${process.env.API_PATH}/partners`).catch((err) =>{ console.error(err) });
    const partners = await response.json();
    
    return { props: { partners } }
}
Giant panda
Is this fetching your Next API or a separate backend?
If it's the latter it's a totally different question not related to this thread.
next api
Giant panda
Well, the same logic from the article applies. Don't fetch your own API in server-side code.
So I have no choice to do it in client side ?
Giant panda
No, I am saying to not fetch your own API and just perform the logic the API endpoint would do in your gSSP
The linked article does exactly that
Oh ok my bad i've not understand that thing, I will apply it
I should so something like this
export async function getServerSideProps() {

    const partners = await prisma.partner.findMany();

    return { props: { partners } }
}
Giant panda
Yes
I will rebuild and deploy my app to test it thx 😄
It works, thank you 🙂