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
Astro Info
If this issue only occurs in one browser, which browser is a problem?
All
Describe the Bug
In
devserver mode, a server island component cannot resolveimport { env } from 'cloudflare:workers';This only happens when
prerenderEnvironmentis set tonode.This is problematic, because
prerenderEnvironmentshould only affect pre-rendered pages. However, server island components get executed inworkerdenvironment on production, regardless of the value ofprerenderEnvironment.Similar bugs can be found in
middleware.ts, where I cannot doconst { env } = await import('cloudflare:workers');(I only do this after checking that page is not pre-rendered viacontext.isPrerendered, so this module should be available as we are running inworkerdenvironment for sure). See https://github.com/CaiJimmy/astro-v6-cf-serverisland-dev-bug/blob/main/src/_middleware.ts for the example (rename tomiddleware.tsif 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