Build error in vercel related to fetching data #50609
Replies: 6 comments 8 replies
-
Are you absolutely sure it works locally? Like I mean The problem as I understand you have it, is that you are trying to reach for port 3000, on the Vercel deploy instance, but there's just nothing running there, because the server is in the process of being build. It is a sort of catch-22, to have the server, you need the build step, but during the build step you want a server to handle the It is worth nothing that other frameworks solve this by using a special So in your case, just skip doing the fetch and import the JSON into the server component directly. You can even just use In terms of architecture it is always a bit odd, at least for me, to make a request to the server for a page, and inside that request, make a request for the same server. Just go get the data you need at component level. |
Beta Was this translation helpful? Give feedback.
-
Yes, it works without problem locally, including next build and this occurs just when trying to deploy it. |
Beta Was this translation helpful? Give feedback.
-
I don't know, that's how it works for me.
If I'm not able to do it with api approach, I'll ditch that api way entirely and try to do it like I mentioned above. |
Beta Was this translation helpful? Give feedback.
-
Since I work with local json data, I removed completely the api approach and did it by using fsPromises and path to find and read data. Also, I want to give credit to Lorenzo Zarantonello, who wrote this blog post in regards to reading local json data in NextJS: https://dev.to/this-is-learning/reading-local-json-data-with-nextjs-part-5-59le |
Beta Was this translation helpful? Give feedback.
-
Thank you, I appreciate that. Now I see how great is this new way of accessing data in Server Components, without needing to use getStaticProps. I'll leave this discussion open for now if someone else wants to share their idea as well. |
Beta Was this translation helpful? Give feedback.
-
i solved the same problem this way. And is Solved for me.Is it right
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hello everybody,
So, I am trying to upload this project that uses local json file and while in development mode and even when building and starting the production server, everything works as intended.
Now, when I try to deploy this project on vercel, I get fetch failed error and I know there's something that I miss with this new app workflow, but I'm unable to pinpoint that problem.
I'll include my project repo, if you want to recreate this same issue on your end.
Here are some screenshots that may help:




Additional information
No response
Example
https://github.com/mariogilezan/e-build
Beta Was this translation helpful? Give feedback.
All reactions