Cloudflare · tool · fg-0222

Wrangler deploy --env production ships without the vars, KV, or D1 bindings defined at the top level

If you see env.DB is undefined in the production environment Worker, the cause and the fix for Cloudflare are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
env.DB is undefined in the production environment WorkerTypeError: Cannot read properties of undefined (reading 'prepare')Variables visible in the default deploy are missing under --env
Cause
Bindings and vars are non inheritable keys in Wrangler config, so a named environment gets none of the top level values. Each environment needs its own copy.
Fix
Repeat vars and every binding block inside each [env.NAME] section, pointing at that environment's resources.
Apply
[env.production] name = "my-worker-production" vars = { API_HOST = "api.example.com" } [[env.production.d1_databases]] binding = "DB" database_name = "prod-db" database_id = "YOUR_DB_ID"
Affected
Wrangler 3 and 4 with named environments, as of October 2026
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun