Skip to content

Astro v6 Cloudflare prerendering environment is too restrictive #15684

@CaiJimmy

Description

@CaiJimmy

Astro Info

Astro                    v6.0.0-beta.17
Node                     v25.6.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             none

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

No response

Describe the Bug

In Astro v5, when using the Cloudflare adapter, the prerendering step (pages with export const prerender = true) was executed in a standard Node.js environment. This allowed the use of native modules (like sharp), WebAssembly instantiation (like satori), and the fs module for local caching during the build process.

In Astro v6 (beta), the @astrojs/cloudflare adapter has introduced a custom prerenderer that executes during astro build within a workerd environment. While this ensures parity with the production runtime, it is a significant breaking regression for the build process because:

  • WebAssembly restrictions: Workerd disallows dynamic WebAssembly compilation (WebAssembly.instantiate), causing libraries like Satori to crash during the build process. There is a workaround for this, though, which involves manually importing the WASM file.
  • Native Modules: Native Node.js modules like Sharp cannot be resolved or loaded in the workerd environment.
  • Filesystem API: Direct fs access (used for caching remote assets during build) results in "operation not permitted".
  • Currently, there is no way for a user to opt-out of the workerd prerenderer to restore the standard Node.js build behavior, making it impossible to generate assets like OG images at build time.

I would argue that for prerending routes, it's not necessary to use workerd environment, because those are converted into static files, and should never encounter with any behaviour mismatch issues in Worker runtime.

The error that would shown in the terminal is something like:

09:49:57   ├─ /index.htmlPOST /__astro_static_paths 200 OK (2ms)
09:49:57 [ERROR] Error: No such module "dist/server/.prerender/chunks/sharp".
  imported from "dist/server/.prerender/chunks/index_BljuEQte.mjs"

What's the expected result?

I would expect prerendered routes to use native Node.js packages that are unavailable in the worker environment.

I have attached a minimal, reproducible example with two branches.

  • main: with Astro v6. The build does not work due to workerd restrictions.
  • astro-v5: With Astro v5, the build works.

Link to Minimal Reproducible Example

https://github.com/CaiJimmy/astro-v6-break-cf-prerender

Participation

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions