Error: Failed to collect page data in production in next.js #54308
-
SummaryBasically APIs are working fine in dev mode. but when its come to production its give me an error that data is not defined or failed to collect page data. so, I guess my Apis are not working in getStaticPaths and getStaticProps. So, what is the proper way to doing it ? how to resolve this issue ? and I tried also in VERCEL but its give me the same error. Can anybody please help me :( Thanks In Advanced <3 ERROR:
this is how am I doing: this is env file:
this is my method:
getSchedule Function:
these methods are working perfectly fine in development mode but I don't know why is not running in production mode.. Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
I mean there's a few things here that raise some questions. First, Second,
Both are in a way, making a big assumption, that the server that responds to
The solution here is to reach for the server with the data, from the build step. Because, during the build step there's no server to handle requests. If If |
Beta Was this translation helpful? Give feedback.
-
Hi everyone! I've one issue when I try to build my Next.js app. This issue is coming from an axios request made on the getStaticPaths on a dynamic page. This is the route /products/[id]. My project has an internal API where I can get the data from, but for some reason when I use npm run build I get the following error: AxiosError: connect ECONNREFUSED 127.0.0.1:8017:55:17.520 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) { Error: Failed to collect page data for /products/[id]17:55:17.540 | at /vercel/path0/node_modules/next/dist/build/utils.js:1158:15 Here is what inside my Page:
|
Beta Was this translation helpful? Give feedback.
-
@SantiGaleazzi You can't Directly call an Api, just make another folder on the root name 'utils' and make the function and implement this functionality on it, I given you an example so, you can understand correctly.
then you can call this function in the getStaticPaths |
Beta Was this translation helpful? Give feedback.
-
I Had the same problem. I was using bash. I switched to zsh and it worked |
Beta Was this translation helpful? Give feedback.
-
I had the same problem. In my case, DB connection was being made. If you are doing createClient, move the call to within a function instead of invoking the function prior. |
Beta Was this translation helpful? Give feedback.
-
I also face the same issue "unable to get the page data for /api/getUser". The solution to this is to perform prisma generate before each build. Full blog for this is in below link. Please do checkout. |
Beta Was this translation helpful? Give feedback.
The work you do in
api/allSchedules
, you should move into thegetStaticProps
function. First do that, then you can think of refactoring.