Next.js Discord

Discord Forum

Prevent fetch calls to api during build when fetch has "force-cache" option

Unanswered
Siberian posted this in #help-forum
Open in Discord
Avatar
SiberianOP
I am using Next.js 15.1.5 with app router. The app is being build in standalone mode in a gitlab pipeline. The container is then sent our servers and runs there.
The problems is during build Next.js tries to prerender pages and the build fails, because it tries to call api, which is of course unreachable during build stage. The exact error is "Static worker exited with code: 1 and signal: null"
I also have a call to "cookies().get()" in my root layout, so all pages are dynamic and rendered at request time.
The problem only appears when I add "cache: 'force-cache'" to a certain fetch. Everything works fine if I remove "force-cahce" from that fetch. But I want Next.js to cache response to that request during runtime. I just don't want it to try to prerender pages during build.
I can't use "export const dynamic = 'force-dynamic' " because docs claim it's equivalent to removing "force-cache".
Is there no way to have both data cache during runtime and disable prerender during builds? I'd love to have cache when I run the app, but I don't need any prerendering

1 Reply

Avatar
Australian Freshwater Crocodile
You might wanna try unstable_cache or the canary ”use cache” to cache the functions that are doing the fetches