🐛 BUG: `wrangler dev` does not pick up edits to `.dev.vars` while it is running

Open
#17,157 0 comments 0 reactions 0 assignees View on GitHub

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

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
  1. npx wrangler dev --port 8799
  2. curl http://127.0.0.1:8799/ → MY_SECRET=one
  3. Change .dev.vars to MY_SECRET=two and wait 10 s
  4. curl http://127.0.0.1:8799/ → still MY_SECRET=one
  5. Restart wrangler dev, curl again → 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.vars changes there trigger a full reload.
  • #4894: feature request for wrangler pages dev only. Closed and moved to a discussion.
  • #16277: the Vite plugin copies file-derived CLOUDFLARE_* values into process.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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.