Which Cloudflare product(s) does this pertain to?
Wrangler core
What version(s) of the tool(s) are you using?
wrangler@latest (reproduced on main)
What is the issue or question you have?
CLOUDFLARE_ENV selects the config environment, but it does not select the matching .env.<environment> / .dev.vars.<environment> files. --env does both. So the two ways of choosing an environment disagree about which env files get loaded.
Steps to reproduce
# .dev.vars.staging
MY_SECRET = "from-staging"
# loads .dev.vars.staging -> MY_SECRET === "from-staging"
npx wrangler dev --env staging
# applies the staging config environment, but does NOT load .dev.vars.staging
CLOUDFLARE_ENV=staging npx wrangler dev
The same applies to .env.<environment>.
Why this looks like a bug rather than intended behaviour
The config loader already treats the two as equivalent — it resolves the environment as --env first, then CLOUDFLARE_ENV, and its own error message says "You have specified the environment ... via the CLOUDFLARE_ENV environment variable." The env-file lookup is the one place that only reads --env.
--env's help text describes it as "Environment to use for operations, and for selecting .env and .dev.vars files", so the file selection is documented as part of choosing an environment, not as an --env-only feature.
Impact
A Worker deployed from CI with CLOUDFLARE_ENV set silently gets the wrong secrets and vars locally — no warning, the values just come from the base .dev.vars instead of the environment-specific one.
I have a fix and tests for this in #15022; happy to close that and work from whatever you decide here.
Which Cloudflare product(s) does this pertain to?
Wrangler core
What version(s) of the tool(s) are you using?
wrangler@latest (reproduced on
main)What is the issue or question you have?
CLOUDFLARE_ENVselects the config environment, but it does not select the matching.env.<environment>/.dev.vars.<environment>files.--envdoes both. So the two ways of choosing an environment disagree about which env files get loaded.Steps to reproduce
The same applies to
.env.<environment>.Why this looks like a bug rather than intended behaviour
The config loader already treats the two as equivalent — it resolves the environment as
--envfirst, thenCLOUDFLARE_ENV, and its own error message says "You have specified the environment ... via the CLOUDFLARE_ENV environment variable." The env-file lookup is the one place that only reads--env.--env's help text describes it as "Environment to use for operations, and for selecting .env and .dev.vars files", so the file selection is documented as part of choosing an environment, not as an--env-only feature.Impact
A Worker deployed from CI with
CLOUDFLARE_ENVset silently gets the wrong secrets and vars locally — no warning, the values just come from the base.dev.varsinstead of the environment-specific one.I have a fix and tests for this in #15022; happy to close that and work from whatever you decide here.