Skip to content

Workers built by Astro 7.4.13 fail at startup: workerd-prelude's top-level await forms a chunk cycle with zod #392

Done

Description

@Madraka

What happens

When try.cloudhal.com is built with Astro 7.4.13 (instead of 7.4.7), its Worker fails at startup with:

Uncaught Error: Top-level await in module is unsettled.

wrangler deploy --dry-run passes. Only a real start fails: wrangler dev, or a deploy. Because of this, try#13 (the move to 0.12.0) keeps astro at 7.4.7.

cloudhal.com runs Astro 7.4.13 without the problem. Its Worker entries come from cloudhal deploy. In try, the Astro / Cloudflare Vite plugin build bundles the entry (src/playground/worker.ts).

Why

@cloudhal/cloudflare/workerd-prelude (packages/cloudflare/src/workerd-prelude.ts) runs const z = await import("zod/v4") at top level. That is the esbuild workaround from ADR-0012. With Astro 7.4.13:

  1. Rollup inlines the prelude into the worker-entry_*.mjs chunk.
  2. zod/v4 goes into its own v4_*.mjs chunk.
  3. That chunk statically imports ./worker-entry_*.mjs back.

So the entry's top-level await waits for a module that waits for the entry, and never settles.

The bisect isolates it to Astro:

Setup Starts?
@cloudhal 0.12.0 only yes
+ wrangler 4.169.0 yes
+ astro 7.4.13, with Vite 8.3.8 no
+ astro 7.4.13, with Vite 8.4.0 no

What to decide

  • Whether a Vite/Rollup-built Worker needs the prelude at all. The esbuild ordering bug it works around is wrangler's bundler. If not, try (and any Astro-bundled entry) drops the import, and the prelude docs say it is for wrangler-bundled entries only.
  • If it is needed: a form without the top-level await cycle, for example a static import, checked against the original "ZodLazy is not a constructor" failure under wrangler's esbuild.
  • A start check, not only a dry run: the try deploy and the template check should start the built Worker once (for example wrangler dev and one request) before they pass.

Done when

  • try runs Astro ≥ 7.4.13 and starts.
  • The admin Worker that cloudhal deploy generates still starts.

🤖 Generated with Claude Code

Activity

  1. Madraka commented on Dec 2, 2026

    @Madraka
    ContributorAuthor

    Local check (2026-12-03)

    I built try main with Astro 7.4.13 (Vite 8.3.8 override, @cloudflare/vite-plugin 1.70.2) and started it with wrangler dev.

    With the prelude import: the Worker fails at startup with Uncaught Error: Top-level await in module is unsettled. The build output shows the cycle:

    • worker-entry_*.mjs contains await import("./v4_*.mjs").
    • That v4_*.mjs facade chunk starts with import "./worker-entry_*.mjs";.

    With import "@cloudhal/cloudflare/workerd-prelude" removed from src/playground/worker.ts: the Worker starts. Every result is the expected playground answer, and there was no ZodLazy or other startup error:

    Request Result
    landing 200
    POST /_playground/session 303 → /sites
    /api/sites lists "Playground Notes"
    /api/auth/* 403 (no sign-in in a playground)
    /mcp the playground's "not available" block

    The esbuild ordering bug the prelude works around does not apply to Rollup output, so a Vite/Astro-bundled entry does not need the prelude.

    Proposed fix

    1. try: drop the prelude import and move to Astro 7.4.13.
    2. Here: make the prelude doc comment and ADR-0012 say it is only for entries that wrangler bundles with esbuild (the cloudhal deploy admin entry). Optionally, the try deploy could start the built Worker once before deploying.

    🤖 Generated with Claude Code

  2. Madraka commented on Dec 2, 2026

    @Madraka
    ContributorAuthor

    Fixed: cloudhal-dev/try#14 dropped the prelude import and moved try to Astro 7.4.13. It is deployed (version 348fa06a); the live smoke passed for landing, session, Studio, API, the visitor site, RSS and reset. #393 documents that the prelude is for esbuild-bundled entries only.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions