Astro Info
Astro v6.2.1
Node v24.11.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?
No response
Describe the Bug
import { env } from "cloudflare:workers" fails under the following conditions:
output: "static"
- Cloudflare
prerenderEnvironment: "node"
- Any route exists that uses
getStaticPaths to generate routes at build time with a route file using the [path].astro pattern.
If all routes are dynamic (server mode for the entire project, or all routes use export const prerender = false) OR fully static including the path (route files like filename.astro with no dynamic route parameter), then it works.
My test case (and where I encountered this in my production projects) is a file endpoint, but I believe the same is true when using this import in regular Astro files.
I cannot use workerd for prerendering -- I have several projects running into this issue and all of them fail in different ways when doing that, in ways that would be impossible or very difficult to change (i.e. our CMS's JS SDK has issues with workerd).
With prerender = true (default) in [page].astro, [test].txt.ts fails with this error:
With prerender = false in [page].astro, [test].txt.ts renders the expected content:
To trigger this behavior in the MRE, start the dev server and visit http://localhost:4567/foo.txt, then uncomment line 2 in /pages/[page].astro and HMR will reload foo.txt showing the error. This happens in a deployed Worker, too.
What's the expected result?
Non-prerendered routes should still work with cloudflare:workers if there are dynamic prerendered routes in the project.
I've tried many (many) things, with no luck, including:
- Using dynamic imports inside the file endpoint's GET method (i.e.
await import("cloudflare:workers").
- Flipping the logic and running in server mode with specific routes opted out using
export const prerender = true.
- Moving this import to various places and passing
env to functions as arguments.
During my troubleshooting I found, but cannot find again now to include here, a bug report with a very similar description, that suggested the two workarounds above, neither of which works in this case. That report said something about having any prerendered dynamic routes changed how the entire project's dependencies were handled, meaning that virtual modules like cloudflare:workers cannot be used, which seems to match this problem. But I'm still able to use other virtual modules like astro:env.
Link to Minimal Reproducible Example
https://github.com/thomas-callahan-collibra/astro-blog-starter-template
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
import { env } from "cloudflare:workers"fails under the following conditions:output: "static"prerenderEnvironment: "node"getStaticPathsto generate routes at build time with a route file using the[path].astropattern.If all routes are dynamic (server mode for the entire project, or all routes use
export const prerender = false) OR fully static including the path (route files likefilename.astrowith no dynamic route parameter), then it works.My test case (and where I encountered this in my production projects) is a file endpoint, but I believe the same is true when using this import in regular Astro files.
I cannot use
workerdfor prerendering -- I have several projects running into this issue and all of them fail in different ways when doing that, in ways that would be impossible or very difficult to change (i.e. our CMS's JS SDK has issues withworkerd).With
prerender = true(default) in[page].astro,[test].txt.tsfails with this error:With
prerender = falsein[page].astro,[test].txt.tsrenders the expected content:To trigger this behavior in the MRE, start the dev server and visit
http://localhost:4567/foo.txt, then uncomment line 2 in/pages/[page].astroand HMR will reloadfoo.txtshowing the error. This happens in a deployed Worker, too.What's the expected result?
Non-prerendered routes should still work with
cloudflare:workersif there are dynamic prerendered routes in the project.I've tried many (many) things, with no luck, including:
await import("cloudflare:workers").export const prerender = true.envto functions as arguments.During my troubleshooting I found, but cannot find again now to include here, a bug report with a very similar description, that suggested the two workarounds above, neither of which works in this case. That report said something about having any prerendered dynamic routes changed how the entire project's dependencies were handled, meaning that virtual modules like
cloudflare:workerscannot be used, which seems to match this problem. But I'm still able to use other virtual modules likeastro:env.Link to Minimal Reproducible Example
https://github.com/thomas-callahan-collibra/astro-blog-starter-template
Participation