🐛 BUG: `wrangler dev` does not pick up edits to `.dev.vars` while it is running
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- nodejs, typescript
- Domain
- cli, developer-experience
Research direction
Start by reproducing with the three-file example and npx wrangler dev. Then read watchPaths in #updateConfig in packages/wrangler/src/api/startDevWorker/ConfigController.ts, and getVarsForDev in packages/dev-helpers/src/dev-vars.ts, which decides which vars file is read. Done when editing .dev.vars triggers a reload and the next request returns MY_SECRET=two without a restart.
Written by the indexing model from the issue text.
Description
What versions & operating system are you using?
wrangler 4.168.0 (latest on npm, 25 Nov 2026), Node v24.22.3, Linux 7.0.0 (Ubuntu 24.04). Code checked on main at 0c06246f0.
Please provide a link to a minimal reproduction
Inline below (3 files).
Describe the Bug
While wrangler dev is running, editing .dev.vars leaves Worker bindings unchanged until the process is restarted. Editing the Wrangler config file does reload, and that reload reads .dev.vars again.
.env* is only a fallback. With no --env-file, getVarsForDev loads a single file: .dev.vars.<env> when --env is set and that file exists, otherwise .dev.vars. It reads .env* only when neither of those files exists and CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV is not "false" (default is on). The defaults are .env, .env.local, and with --env also .env.<env> and .env.<env>.local, merged in that order. --env-file skips .dev.vars and uses the given paths instead, under the same flag. Those files are unwatched too. The steps below cover .dev.vars only.
Steps
wrangler.jsonc
{ "name": "devvars-repro", "main": "src/index.js", "compatibility_date": "2026-11-01" }
src/index.js
export default {
fetch(request, env) {
return new Response(`MY_SECRET=${env.MY_SECRET}\n`);
},
};
.dev.vars
MY_SECRET=one
npx wrangler dev --port 8799curl http://127.0.0.1:8799/→MY_SECRET=one- Change
.dev.varstoMY_SECRET=twoand wait 10 s curl http://127.0.0.1:8799/→ stillMY_SECRET=one- Restart
wrangler dev,curlagain →MY_SECRET=two
Expected: after step 3, wrangler dev reloads the way it does for a config change, and step 4 returns MY_SECRET=two.
Why (main @ 0c06246f0): in packages/wrangler/src/api/startDevWorker/ConfigController.ts, #updateConfig builds watchPaths at lines 836–848. Inside !getDisableConfigWatching() && input.dev?.watch !== false, that list is newConfig.dependencies under --experimental-new-config, otherwise just fileConfig.configPath. #updateConfig then calls resolveConfig (line 861), which calls resolveBindings (line 455) → getBindings → getVarsForDev (packages/dev-helpers/src/dev-vars.ts, called from packages/dev-helpers/src/miniflare-options.ts at line 1183). The vars files are never added to the watcher. #watchConfig (line 742) only handles change.
Related:
- #8669, fixed by #8685: the same gap in the Vite plugin.
.dev.varschanges there trigger a full reload. - #4894: feature request for
wrangler pages devonly. Closed and moved to a discussion. - #16277: the Vite plugin copies file-derived
CLOUDFLARE_*values intoprocess.env, so a later resolve in the same process keeps the old value. Different cause.
Fix: I've already written a fix with tests: https://github.com/cloudflare/workers-sdk/compare/main...beartester34:workers-sdk:beartester34/fix/dev-vars-watch
It adds a small dev-helpers function that lists the files getVarsForDev may read, and ConfigController watches them, including creating or deleting one, since that can change which file wins. These files get their own watcher on their directories, because chokidar does not reliably notice a missing file being created when it watches the file itself. 9 new tests fail on main and pass with the fix. Happy to open it as a PR whenever suits you.
Please provide any relevant error logs
No errors. Requests keep returning the old value, and the dev log shows no reload after the .dev.vars edit.
I found this with AI tools in my own detection-and-fix workflow; I reproduced it myself on the released wrangler and read the code paths above.
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 1.7k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 282
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/workers-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
cloudflare/workers-sdk#17215 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
cloudflare/workers-sdk#17189 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudflare/workers-sdk#17187 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
cloudflare/workers-sdk#17175 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/workers-sdk#17174 ·
Maintainers usually reply within 1 day
All issues in cloudflare/workers-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
earendil-works/pi#12615 ·
Maintainers usually reply within 1 day
-
My Caps shows "Shared" on private Caps that were never sharedPossibly taken @AksharP5 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CapSoftware/Cap#4569 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainers usually reply within 2 days