Next.js Discord

Discord Forum

Error to build with private routes (fetch with authorization)

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
Hello,

I'm currently working on developing a dashboard using Next.js 14 and SSR. I've encountered a challenge with a private route that requires users to be logged in on the frontend. This is necessary to set the authorization header for sending requests to the backend, specifically for making API calls in the /items endpoint.

While the implementation seems correct and functional during development, I'm facing an issue when building the project. The error message I'm encountering is as follows:

Error: Request failed. false
    at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ItemsTemplate (/home/alexis/Documents/DigiChanges/next-experience/.next/server/app/items/page.js:1:9304)
Error: Request failed. false
    at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ItemsTemplate (/home/alexis/Documents/DigiChanges/next-experience/.next/server/app/items/page.js:1:9304)

Error occurred prerendering page "/items". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Request failed. false
    at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
 ✓ Generating static pages (11/11) 

> Export encountered errors on following paths:
        /items/page: /items


It appears that the build attempts to make an API call during the build process, but it fails because the authorization header is not available due to the absence of a logged-in state.

I would greatly appreciate any assistance or insights into resolving this issue. Thank you in advance!

12 Replies

@American black bear Hello, I'm currently working on developing a dashboard using Next.js 14 and SSR. I've encountered a challenge with a private route that requires users to be logged in on the frontend. This is necessary to set the authorization header for sending requests to the backend, specifically for making API calls in the /items endpoint. While the implementation seems correct and functional during development, I'm facing an issue when building the project. The error message I'm encountering is as follows: ts Error: Request failed. false at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ItemsTemplate (/home/alexis/Documents/DigiChanges/next-experience/.next/server/app/items/page.js:1:9304) Error: Request failed. false at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ItemsTemplate (/home/alexis/Documents/DigiChanges/next-experience/.next/server/app/items/page.js:1:9304) Error occurred prerendering page "/items". Read more: https://nextjs.org/docs/messages/prerender-error Error: Request failed. false at HttpService.request (/home/alexis/Documents/DigiChanges/next-experience/.next/server/chunks/993.js:1:3142) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) ✓ Generating static pages (11/11) > Export encountered errors on following paths: /items/page: /items It appears that the build attempts to make an API call during the build process, but it fails because the authorization header is not available due to the absence of a logged-in state. I would greatly appreciate any assistance or insights into resolving this issue. Thank you in advance!
try adding export const revalidate = 0 to force the page out of static rendering
better fixes exist but require you to post a simplified reproduction of your page here
so we know how to fix it
American black bearOP
I can provide you the repositoy, its open source, or fragments of the code i use in that part @joulev
yes then give me the source'
@joulev try adding `export const revalidate = 0` to force the page out of static rendering
this sounds like the simplest solution to the problem
American black bearOP
Where should i put that?
American black bearOP
Thank you 😄

So this will remove the cache
from building
Original message was deleted
I think it’s at least good practice to put it below import statements. The value is 0 not false, they are different
American black bearOP
@joulev Thank you very much !