Skip to content

[v6 / Cloudflare] Server island component cannot access cloudflare:workers module in dev environment #15946

@CaiJimmy

Description

@CaiJimmy

Astro Info

Astro                    v6.0.4
Node                     v25.8.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             none

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

All

Describe the Bug

In dev server mode, a server island component cannot resolve import { env } from 'cloudflare:workers';

This only happens when prerenderEnvironment is set to node.

This is problematic, because prerenderEnvironment should only affect pre-rendered pages. However, server island components get executed in workerd environment on production, regardless of the value of prerenderEnvironment.

Similar bugs can be found in middleware.ts, where I cannot do const { env } = await import('cloudflare:workers'); (I only do this after checking that page is not pre-rendered via context.isPrerendered, so this module should be available as we are running in workerd environment for sure). See https://github.com/CaiJimmy/astro-v6-cf-serverisland-dev-bug/blob/main/src/_middleware.ts for the example (rename to middleware.ts if you want to test this).

What's the expected result?

Server island components should be able to import from cloudflare:workers.

And middleware should be able to use this module too, after checking that it's not pre-render environment.

Link to Minimal Reproducible Example

https://github.com/CaiJimmy/astro-v6-cf-serverisland-dev-bug/

Participation

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

Metadata

Metadata

Assignees

Labels

- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)pkg: cloudflareRelated to the Cloudflare adapter

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions