Skip to content

Cloudflare 14.3.1: every prerendered page builds to [object Object] with nodejs_compat and compatibility_date >= 2025-10-01 #18009

Closed

Description

@Jibbscript

Astro Info

astro                     7.3.2
@astrojs/cloudflare       14.3.1
wrangler                  4.131.2
workerd                   1.20260915.1
miniflare                 5.20260915.0-alpha
Node                      v22.23.1
Package manager           npm
OS                        macOS

Describe the Bug

With nodejs_compat enabled and a compatibility_date of 2025-10-01 or later, every prerendered route builds to a 15-byte file containing the literal string [object Object] instead of HTML.

The build reports success — no error, no warning. SSR routes are unaffected; only prerender = true routes are corrupted.

This is easy to miss precisely because the build is green. The broken output only surfaces once it's served — it reached our production site this way, on every static page at once.

What's the expected result?

dist/client/index.html contains the rendered HTML.

Instead it contains exactly [object Object] (15 bytes).

Link to Minimal Reproducible Example

Four files, no integrations, no app code:

package.json

{
  "name": "cf-prerender-repro",
  "type": "module",
  "private": true,
  "scripts": { "build": "astro build" },
  "dependencies": {
    "@astrojs/cloudflare": "14.3.1",
    "astro": "7.3.2",
    "wrangler": "4.131.2"
  }
}

astro.config.mjs

import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
  output: 'server',
  adapter: cloudflare(),
});

wrangler.toml

name = "cf-prerender-repro"
compatibility_date = "2025-12-01"
compatibility_flags = ["nodejs_compat"]

src/pages/index.astro

---
export const prerender = true;
---
<html><body><h1>hello</h1></body></html>
npm install && npm run build && cat dist/client/index.html

Expected: <!DOCTYPE html><html><body><h1>hello</h1></body></html>
Actual: [object Object]

Isolation

Each row is that same reproduction with only wrangler.toml changed:

compatibility_date compatibility_flags dist/client/index.html
2025-12-01 [] 117 bytes, correct HTML
2025-12-01 ["global_fetch_strictly_public"] 117 bytes, correct HTML
2025-12-01 ["nodejs_compat"] 15 bytes, [object Object]
2025-09-30 ["nodejs_compat"] 117 bytes, correct HTML
2025-10-01 ["nodejs_compat"] 15 bytes, [object Object]
2025-12-01 ["nodejs_compat", "disable_nodejs_process_v2"] 117 bytes, correct HTML

The trigger is enable_nodejs_process_v2, which becomes default-on for nodejs_compat at compatibility_date >= 2025-10-01. The date boundary is exactly 2025-09-30 (fine) → 2025-10-01 (broken), and adding disable_nodejs_process_v2 is a complete workaround.

Where it goes wrong

Instrumenting astro/dist/core/build/generate.js where the prerendered body is read shows the corruption already present in the response coming back from the prerender worker:

/  status=200  content-type=text/html  len=15  head="[object Object]"

So the body is bad before Astro writes the file — it originates inside the prerender worker, not in the build's file handling.

It looks like the streaming render path. Patching the adapter's own handler:

  // node_modules/@astrojs/cloudflare/dist/utils/handler.js
- const app = createApp();
+ const app = createApp({ streaming: false });

…makes every prerendered page render correctly (our homepage went from 15 bytes to 77,209 bytes of valid HTML). That's a local patch rather than a fix, but it narrows the interaction to streaming + process v2.

Possibly related: our app already carried this comment from an earlier version pairing, so a streaming variant of this may predate the current releases —

// Astro 6.1.9 + @astrojs/cloudflare 13.2.1 can stream plain render instructions
// as "[object Object]" for this app's SSR pages. Non-streaming renders full HTML.
const app = createApp({ streaming: false });

Since nodejs_compat plus a current compatibility_date is a common Workers setup, this likely affects a fair number of projects, and the silent-success failure mode means they may not find out until it's deployed.

Participation

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

Activity

  1. added
    triage: in progress
    on Sep 15, 2026
  2. astro-factory commented on Sep 15, 2026

    @astro-factory
    Contributor

    Triage complete

    • Prepare the workspace: ready
    • Install dependencies: complete
    • Build the project: complete
    • Reproduce the issue: confirmed
    • Diagnose the cause: high confidence
    • Verify the diagnosis: bug
    • Attempt a fix: verified
    • Publish the result: set triage: fix pending

    • Reproduced: Yes — dist/client/index.html contains [object Object] (15 bytes) instead of HTML when nodejs_compat is enabled
    • Exploration: Yes — View branch
    • Unit Test: Yes — packages/integrations/cloudflare/test/prerender-nodejs-compat.test.ts
    • Priority: P4: important. This silently corrupts all prerendered output for a common Cloudflare Workers configuration (nodejs_compat), and the build reports success with no warnings. The disable_nodejs_process_v2 workaround exists but is non-obvious.

    When workerd runs with nodejs_compat, the process global satisfies Astro's isNode check in packages/astro/src/runtime/server/render/util.ts, causing renderPage to use renderToAsyncIterable and pass the resulting AsyncIterable to workerd's Response constructor. Workerd does not support AsyncIterable as a body (it's a non-standard Node.js extension), so it stringifies the object to [object Object]. This exact issue was previously fixed in PR #16720, but that fix was reverted in PR #16997 because the renderToReadableStream fallback caused a build-time performance regression for large sites.

    I found a potential fix for this issue. The fix adds isWorkerd detection (via navigator.userAgent === 'Cloudflare-Workers') and, when in workerd, wraps the AsyncIterable with ReadableStream.from() instead of passing it directly to the Response constructor. This preserves the faster renderToAsyncIterable rendering path (avoiding the performance regression that caused the previous revert) while producing a standard BodyInit type that workerd accepts.

    Try this fix

    You can test this fix right now without waiting for a release:

    # astro
    npm i https://pkg.pr.new/astro@46af878
    # @astrojs/cloudflare
    npm i https://pkg.pr.new/@astrojs/cloudflare@46af878

    If this fixes your issue, please leave a comment letting us know (for example
    "confirmed, this fixes it"). A pull request will then be opened to get it merged.

    Full Triage Report

    Reproduction

    Confirmed with a minimal reproduction: astro.config.mjs with output: 'server' + adapter: cloudflare(), wrangler.toml with nodejs_compat, and a single prerendered page. Build succeeds but output is [object Object].

    wrangler.toml config dist/client/index.html
    compatibility_flags = ["nodejs_compat"] [object Object] (15 bytes) — BROKEN
    compatibility_flags = [] Correct HTML
    compatibility_flags = ["nodejs_compat", "disable_nodejs_process_v2"] Correct HTML

    Root Cause

    In packages/astro/src/runtime/server/render/util.ts:

    export const isNode =
        typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]';

    With nodejs_compat, workerd's process global passes this check. In packages/astro/src/runtime/server/render/page.ts, the streaming path then uses renderToAsyncIterable and passes the AsyncIterable<Uint8Array> to new Response(body, ...). Workerd's Response constructor doesn't support AsyncIterable (a non-standard Node.js extension) and falls back to .toString(), producing [object Object].

    Instrumentation confirmed: isNode: true, isDeno: false, streaming: true inside workerd with nodejs_compat.

    History

    Fix

    Added isWorkerd detection and ReadableStream.from() wrapping in the workerd branch (keeps fast renderToAsyncIterable rendering, wraps output to standard ReadableStream for Response constructor compatibility).

    Changes

    • packages/astro/src/runtime/server/render/util.ts — Added isWorkerd constant
    • packages/astro/src/runtime/server/render/page.ts — Wrap AsyncIterable with ReadableStream.from() in workerd
    • packages/integrations/cloudflare/test/prerender-nodejs-compat.test.ts — Integration test
    • .changeset/neat-dingos-sip.md — astro: patch

    Verification

    • ✅ With nodejs_compat: correct HTML output
    • ✅ Without nodejs_compat: correct HTML output (no regression)
    • ✅ All 14 Cloudflare prerender tests pass
    • ✅ All 307 core render unit tests pass
    • ✅ No TypeScript or lint errors

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  3. added
    - P4: important
    pkg: astro
    pkg: cloudflare
    triage: fix pending
    and removed
    triage: in progress
    on Sep 15, 2026
  4. matthewp commented on Sep 16, 2026

    @matthewp
    Contributor

    Bot, I can confirm this fixes it.

  5. added
    triage: fix verified
    and removed
    triage: fix pending
    on Sep 16, 2026
  6. astro-factory commented on Sep 16, 2026

    @astro-factory
    Contributor

    The fix has been verified! A pull request has been created: #18011

  7. added a commit that references this issue on Sep 16, 2026
    558b301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantpkg: astropkg: cloudflaretriage: fix verified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions