Next.js Discord

Discord Forum

All data fetches failing but build passing

Unanswered
Patrick MacDonald posted this in #help-forum
Open in Discord
On build all my data fetches show an error During prerendering, headers() rejects when the prerender is complete. Typically these errors are handled by React but if you move headers() to a different context by using setTimeout, after, or similar functions you may observe this error and you should handle it in that context. This occurred at route "/...

I'm using use cache after checking auth in a child function like the docs show. every error is handled in a try catch and the build passes. does this effect my caching in any way? or is next just trying to make the pages static but cant because of the auth check it cant and I should iggnore these?
Error fetching settings: Error: During prerendering, `headers()` rejects when the prerender is complete. Typically these errors are handled by React but if you move `headers()` to a different context by using `setTimeout`, `after`, or similar functions you may observe this error and you should handle it in that context. This occurred at route "/tracker".
    at new Promise (<anonymous>)
    at async o (src/dal/transactions.ts:17:23)
  15 | export async function getActiveRentals(): Promise<DbResult<Transaction[]>> {
  16 |   try {
> 17 |     const { orgId } = await auth.protect();
     |                       ^
  18 |     if (!orgId) throw new Error("Organization selection is required.");
  19 |
  20 |     const data = await getActiveRentalsDb(orgId); {// <---- this would be the one of the functions that use "use cache" same issue with "use cache: remote" 
  route: '/tracker',
  expression: '`headers()`',
  digest: 'HANGING_PROMISE_REJECTION'
}

0 Replies