Skip to content

@astrojs/cloudflare doesn't correctly forward wrangler vars to Astro #16790

Description

@alexanderdombroski

Astro Info

Astro                    v6.3.5
Vite                     v7.3.3
Node                     v24.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/cloudflare (v13.5.2)
Integrations             none

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

No response

Describe the Bug

The cloudflare adapter isn't fully compatible with astro:env.

Cloudflare's import { env } from "cloudflare:workers" (useable in workerd runtimes) correctly loads vars from the wrangler.jsonc, and the adapter is supposed to forward that env object to be used in Astro's astro:env API. See cloudflare integration code. For some unknown reason, variables that originated from the wrangler.jsonc aren't forwarded.

See related issue discussing what should be expected behavior.

Workaround: Import the env object from "cloudflare:workers" instead of "astro:env", or make variables available during build time and use astro:env.

What's the expected result?

Environment variables defined in the vars field of wrangler.jsonc and env.schema of astro.config.mjs should be importable from "astro:env/client" or "astro:env/server".

Link to Minimal Reproducible Example

https://github.com/alexanderdombroski/astro-cloudflare-env

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: cloudflareRelated to the Cloudflare adaptertriage: fix pendingReporter needs to verify the triage bot fix works

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions