Expecting props to be populated which are not available during prerendering
When deploying a Next.js application to Vercel, the /my_page failed to prerender at build time, resulting in the following error:
TypeError: Cannot read properties of undefined
The error occurred because the backend API endpoint (api/my_endpoint) was not properly integrated on Render.com, causing Next.js to fail when trying to fetch data during the build process. This worked locally since the API was accessible.
Locally:
The /api/my_endpoint returned data when accessed via Thunder Client or directly in the browser. The Next.js application successfully pre-rendered the /my_page page during development.
Deployed Environment:
On Render.com, accessing the /api/my_endpoint through the browser resulted in a server error. This caused the Next.js build to fail as it couldn’t retrieve data from the API for prerendering.