Nextjs Prod build error #66268
-
|
TypeError: fetch failed Anyone know why this error is coming on npm run build? Please help me on this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
|
Hi, You are most likely fetching your own server's API endpoint, but during build time there's no API endpoint, because the server is not build just yet. Instead of fetching from your own API endpoint, inline the code that gets the data you need, into your server component, which is one of the reasons to have server components in the first place. The link above summarizes the problem, please do read through it. |
Beta Was this translation helpful? Give feedback.
-
|
@icyJoseph so i must add a Router.ts for this page in path But how i using the return data in Page? and then would it be necessary to add an api/route.ts file to every server-side page? Would that be too cumbersome? |
Beta Was this translation helpful? Give feedback.
Hi,
You are most likely fetching your own server's API endpoint, but during build time there's no API endpoint, because the server is not build just yet.
Instead of fetching from your own API endpoint, inline the code that gets the data you need, into your server component, which is one of the reasons to have server components in the first place.
The link above summarizes the problem, please do read through it.