Skip to content

[wrangler] Respect CLOUDFLARE_ENV when loading .env and .dev.vars files - #15282

Open
shubhxho wants to merge 3 commits into
cloudflare:mainfrom
shubhxho:fix/cloudflare-env-dotenv-files
Open

[wrangler] Respect CLOUDFLARE_ENV when loading .env and .dev.vars files#15282
shubhxho wants to merge 3 commits into
cloudflare:mainfrom
shubhxho:fix/cloudflare-env-dotenv-files

Conversation

@shubhxho

@shubhxho shubhxho commented Aug 20, 2026

Copy link
Copy Markdown

Fixes #15068.

CLOUDFLARE_ENV already picks the Wrangler config environment. The .env / .dev.vars lookups only looked at --env, so this:

CLOUDFLARE_ENV=staging wrangler dev

activated staging config but still loaded the top-level env files.

Those lookups now use the same fallback the config loader does (--env, then CLOUDFLARE_ENV). I left StartDevWorkerInput.env alone — that's the CLI flag, and writing the env var into it made the redirected-config fixture report a mismatch as coming from --env.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: CLOUDFLARE_ENV is already documented as an alternative to --env. This just makes the env-file lookup match that.

Open in Devin Review

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 20, 2026
@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team August 20, 2026 14:46
@workers-devprod

workers-devprod commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/cloudflare-env-dot-env-files.md: [@cloudflare/wrangler]
  • packages/vite-plugin-cloudflare/playground/vitest-setup.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/dev.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/startDevWorker/ConfigController.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/type-generation/index.ts: [@cloudflare/wrangler]

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15282

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15282

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15282

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15282

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15282

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15282

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15282

miniflare

npm i https://pkg.pr.new/miniflare@15282

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15282

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15282

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15282

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15282

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15282

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15282

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15282

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15282

wrangler

npm i https://pkg.pr.new/wrangler@15282

commit: 7c0839a

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c0839a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

devin-ai-integration[bot]

This comment was marked as resolved.

shubhxho and others added 3 commits August 21, 2026 03:24
--env already picked the matching .env.<env> and .dev.vars.<env>
files, but CLOUDFLARE_ENV only switched the config environment. Use
the same fallback the config loader uses so the two stay in sync.
react-spa headers/redirects has been dying at the default 50s hook
timeout on macos-latest, including on unrelated PRs.
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@shubhxho
shubhxho force-pushed the fix/cloudflare-env-dotenv-files branch from 871b48a to 7c0839a Compare August 20, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

CLOUDFLARE_ENV does not select .env.<environment> / .dev.vars.<environment> files, but --env does

2 participants