- 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