Skip to content

astro/cloudflare doesn't use environment vars specified in wrangler config or adhere to CLOUDFLARE_ENV when running/building #14540

Description

@calumpeak

Astro Info

Astro                    v5.14.5
Node                     v24.7.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare

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

No response

Describe the Bug

Possible regression

I set .env.development and .env.production to contain CLOUDFLARE_ENV=dev and CLOUDFLARE_ENV=prod to utilise the env variables specified in my wrangler.jsonc { env: { dev: { vars: {... however when running astro with the cloudflare plugin it no longer picks up the variables in my wrangler config and I have to duplicate them into .env.development and .env.production to build the application.

This error appears
The following environment variables defined in env.schema are invalid:

(my example doesn't throw an error, just doesn't render the environment variable)

What's the expected result?

Cloudflare plugin should respect CLOUDFLARE_ENV as per https://developers.cloudflare.com/workers/vite-plugin/reference/cloudflare-environments/#combining-cloudflare-environments-and-vite-modes

It should utilise vars from the matching wrangler variable namespace and load those into the application based upon CLOUDFLARE_ENV setting and mode.

Link to Minimal Reproducible Example

https://github.com/calumpeak/env-repro

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: nice to haveNot breaking anything but nice to have (priority)feat: envrelated to the way astro handles `.env` or `import.meta.env` or `process.env` (scope)pkg: cloudflareRelated to the Cloudflare adapter

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions