895 words
4 minutes

Astro Cloudflare “Fetch API cannot load: /”: Fix Prerender Failures

2026-08-19
Astro
Astro
/
Cloudflare
/
JavaScript
/
Troubleshooting

When an Astro Cloudflare build fails with Fetch API cannot load: /, the failure is usually happening during server-side prerendering, not in a browser request. The Cloudflare adapter is executing the prerender in workerd, and a server-side fetch() has received a relative URL such as /.

Find that build-time fetch first. Replace it with a direct data call or an absolute URL when the request really must go through HTTP. If the page or one of its dependencies needs Node-only APIs, set the adapter’s prerenderEnvironment to node as a targeted fallback. That changes the prerender environment; it does not turn every on-demand request into a Node runtime.

Find the fetch that runs during the build#

Search application code and integration configuration before changing the adapter:

Terminal window
rg -n 'fetch\(|new URL\(|Astro\.url|prerender' src astro.config.mjs
pnpm build

Pay attention to code imported by a page with prerender = true, content loaders, layout data functions, and dependencies that perform a request while a module is evaluated. The visible / in the error is the URL that workerd rejected; it may come from your code or a package called by it.

These two cases are different:

// Browser-side code: the browser can resolve this against the current page.
const response = await fetch('/api/data')
// Build/server-side code: give the request an absolute URL or avoid the loopback request.
const response = await fetch(new URL('/api/data', Astro.url))

The second form still requires the target to exist at build time. For a prerendered page, a direct function or data-layer call is often more reliable than making the build call its own API route. Do not “fix” the message by making every browser fetch absolute; the relevant question is which runtime executes the call.

Understand the Astro Cloudflare runtime boundary#

The current Astro Cloudflare adapter guide documents workerd as the default prerender environment for Astro 6 with adapter v13. The workerd runtime is close to Cloudflare’s production environment, but it does not support every Node API or package shape. CommonJS-only dependencies and packages that assume Node built-ins are frequent reasons to test the alternate environment.

If the failing code genuinely needs Node during prerender, configure the adapter explicitly:

import { defineConfig } from 'astro/config'
import cloudflare from '@astrojs/cloudflare'
export default defineConfig({
adapter: cloudflare({
prerenderEnvironment: 'node',
}),
})

Use this as a compatibility decision, not a blanket workaround. The option is intended for prerendered pages that depend on Node APIs or packages incompatible with workerd. On-demand pages still run in the Cloudflare runtime after deployment.

Choose the smallest safe repair#

Use the evidence from the failing stack to choose one of these repairs:

EvidenceRepairWhy
Your code calls fetch('/') or fetch('/api/...') while prerenderingUse a direct data function or an absolute URL with a known baseA build-time server fetch needs a resolvable URL and a live target
A dependency uses Node APIs only while a page is prerenderedSet prerenderEnvironment: 'node'The adapter provides a Node-compatible build-time boundary
The dependency is CommonJS-only or has an incompatible exportUpgrade, replace, or prebundle it; then retest workerdSwitching environments can hide a dependency problem that will return elsewhere
The failing fetch is browser-only but appears in the build stackMove it behind client execution or guard the build pathA browser URL should not execute while generating static HTML

Do not add output: 'server' solely because this error mentions Cloudflare. Output mode decides whether routes are prerendered or rendered on demand; it does not automatically make a relative server fetch valid. Choose the output mode from the application’s rendering requirements.

The GitHub issue withastro/astro #16190 shows the same class of Astro 6 + Cloudflare adapter symptom: a workerd build reports Fetch API cannot load: /. The issue was closed without a planned fix because a reproduction was not established, which is why locating the exact call in your project matters more than copying a universal config change.

Rebuild and test both rendering paths#

After the smallest change, rebuild from a clean command boundary:

Terminal window
pnpm build

Then verify the result according to the chosen output mode:

  • request a prerendered page and confirm its HTML is generated;
  • request an on-demand page through the deployed Worker, if the project has one;
  • exercise the API or binding-backed route used by the page;
  • check that a Node-only dependency did not move into browser code accidentally.

If the site also uses sessions or Cloudflare bindings, keep that deployment concern separate from prerender resolution. The Astro Cloudflare session binding guide covers a binding-specific failure, while the Cloudflare Pages and Workers file-limit guide covers a static output decision.

The reliable sequence is: identify the server-side fetch, decide whether it should be an HTTP request at build time, and use Node prerendering only for a demonstrated compatibility boundary. A successful local build is useful evidence, but the deployed rendering path still needs a request-level check.

FAQ#

Q: Is fetch('/api/data') always invalid in Astro?#

A: No. It is normal in browser code after a page loads. It becomes a problem when the same call executes during server-side prerendering, where the build runtime may not have a current request origin or a live local API route.

Q: Does prerenderEnvironment: 'node' make the deployed Worker run on Node?#

A: No. The option controls the environment used for prerendering. On-demand pages continue to use the Cloudflare runtime after deployment.

Q: Should I switch every Astro Cloudflare project from workerd to Node?#

A: No. Keep the default workerd environment when the code and dependencies support it. Switch only when the build evidence points to a Node API or incompatible package that you cannot remove or replace.

References:

Astro Cloudflare adapter: prerender environment

Astro issue #16190: Astro 6 + Cloudflare adapter

Cloudflare Workers compatibility dates

Astro Cloudflare “Fetch API cannot load: /”: Fix Prerender Failures
https://laplusda.com/en/posts/astro-cloudflare-fetch-api-cannot-load/
Author
Zero
Published at
2026-08-19
License
CC BY-NC-SA 4.0
Was this article useful?

Report a typo or broken link, or suggest a related topic.