-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[v6 / Cloudflare] Server island component cannot access cloudflare:workers module in dev environment #15946
Description
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.