Workers - Declare required secrets in your Wrangler configuration
Key Points
- Declare required secrets in wrangler config
- Type generation works in CI without env files
- Deploy fails if required secrets are missing
Summary
The new secrets configuration property (secrets.required) lets you declare the secret names a Worker needs in your wrangler.toml / wrangler.jsonc. Wrangler uses that list for local development, type generation, and deploy-time validation so missing secrets are caught earlier and CI-friendly typing works without env files.
Key Points
-
Configure required secrets in your Wrangler config:
JSON example:
{ "secrets": { "required": ["API_KEY", "DB_PASSWORD"] } }TOML example:
[secrets] required = ["API_KEY", "DB_PASSWORD"] -
Local development:
wrangler devandvite devwill load only keys listed insecrets.requiredfrom.dev.vars/.env/process.env. Extra keys are ignored. Missing required secrets produce a logged warning listing names. -
Type generation:
wrangler typesgenerates typed secret bindings fromsecrets.required(not inferred from env files), enabling safe typegen in CI. Per-environment secrets become optional in the aggregated Env type if they only exist for some environments. -
Deploy validation:
wrangler deployandwrangler versionsvalidate that each name insecrets.requiredis configured for the Worker and will fail with an error listing any missing secrets.
Recommended actions
- Add all required secret names to
secrets.requiredin your Wrangler config. - Ensure those secrets are set in your Cloudflare Worker environments (or in local
.dev.varsfor development). - Run
wrangler typesin CI to produce consistent typed bindings without relying on env files.