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

Aperta
#17,157 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
282

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.