Skip to content

Prerender error with @astrojs/cloudflare: build exits 0 and emits truncated HTML (v7 alpha) #17047

@mikepage

Description

@mikepage

Astro Info

Astro                    v7.0.0-alpha.2
Vite                     v8.0.16
Node                     v24.15.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare (v14.0.0-alpha.1)
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response (build-time issue)

Describe the Bug

When a page throws during prerendering with the Cloudflare adapter (prerendering runs inside workerd), astro build:

  • exits with code 0 and logs [build] Complete!
  • still writes the page to dist/client, truncated at the exact point of the throw (mid-<head>, no </body>/</html>)

The trigger in the reproduction is the Fonts API: rendering <Font cssVariable="--font-open-sans" /> for a cssVariable that was never registered in fonts throws FontFamilyNotFound — but the underlying problem appears general to any exception thrown during prerendering in the workerd runtime.

Truncated output (full file contents):

<!DOCTYPE html><html lang="en"> <head><meta charset="utf-8"><title>workerd exit code repro</title><!-- --font-open-sans is not registered in astro.config.mjs -> FontFamilyNotFound -->

Whether the error is visible at all is environment-dependent (same versions):

  • Linux (workerd-linux-64, observed in a containerized CI build of a larger project): workerd prints Uncaught exception: ... FontFamilyNotFound: No data was found for the \"--font-open-sans"` family passed to the `` component.` to stderr for every page — but the build still exits 0 and the truncated pages are written.
  • macOS (workerd-darwin-arm64): nothing is printed at all, even with 21 prerendered pages. The error is fully swallowed.

So in CI there is no reliable signal that the build is broken — exit code is 0, and on some platforms the log stream is clean too. Deploying the output produces blank pages.

Switching the page to the registered cssVariable (--font-roboto) produces a complete, correct document, confirming the truncation is caused by the thrown error.

Reproduce:

npm install
npm run build; echo "exit code: $?"   # -> exit code: 0, '[build] Complete!'
cat dist/client/index.html             # -> truncated mid-<head>
find dist/client -name '*.html' | xargs -I{} sh -c 'tail -c 200 {} | grep -q "</html>" || echo "truncated: {}"'

What's the expected result?

A page that throws during prerendering should fail the build with a non-zero exit code (as it does with the Node adapter / non-workerd prerendering), or at minimum the error should be surfaced and the truncated page should not be emitted as if successful.

Link to Minimal Reproducible Example

https://github.com/mikepage/astro-v7-workerd-exit-code

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: cloudflareRelated to the Cloudflare adapter

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions