Next.js Discord

Discord Forum

Error: During prerendering, fetch() rejects when the prerender is complete.

Unanswered
Molossus of Epirus posted this in #help-forum
Open in Discord
Molossus of EpirusOP
Hi everyone. I'm tasked with migrating an old Next.js project to the latest Next.js 16 with Cache Components. Inside one of our dynamic components we have an API call using the native fetch() wrapped in a try/catch block. In our catch block we do some logic and also log the error with console.error so we kown what went wrong. I'm noticing that running a full production build with next build is showing a lot of logs with

"Error: During prerendering, fetch() rejects when the prerender is complete. Typically these errors are handled by React but if you move fetch() to a different context by using setTimeout, after, or similar functions you may observe this error and you should handle it in that context."

coming from that API call. The builds passes fine and everything seems to work, but my terminal is full of those logs. I'm suspecting that as the error mentions this is just normal behavior in Next.js during prerendering and probably it's fine to ignore, but I haven't found anything about this in the official docs. Is this the expected behavior?

A minimal example of what I'm doing is:

try {
  const res = await fetch("my-api");
  
  // some business stuff
} catch (error) {
  //some business stuff
  console.error(error) //<- This is getting called during prerender
}

0 Replies