Home/Wiki Errors/Cloudflare Workers
Cloudflare Workers / Deployment

Environment variables not working in Cloudflare Workers / wrangler

A variable available in local dev is not available in the Worker runtime or production build.

Cloudflare Workers env vars not workingwrangler env variable binding not foundCloudflare .dev.vars production
Paste an error to match it against the wiki. / 粘贴报错后自动匹配。

Error text / 报错原文

  • Environment variable is not defined
  • binding not found
  • vars ignored

What it means

A variable available in local dev is not available in the Worker runtime or production build.

Most common causes

  • Local .env or .dev.vars is not deployed to production
  • wrangler.toml vars differ by environment
  • Secret was set in dashboard but not for the selected environment
  • Build-time and runtime variables are confused

Fastest fix

  • Check wrangler.toml and selected environment
  • Set secrets with wrangler secret put
  • Restart local dev after editing .dev.vars
  • Log only variable presence, not values

Safe fix

  • Maintain .env.example or .dev.vars.example
  • Use environment-specific config blocks
  • Validate required bindings at startup
  • Keep production secrets out of source control

What not to do

  • Do not commit .dev.vars with real secrets
  • Do not assume Vite env variables exist at Worker runtime
  • Do not print secret values in logs

How to confirm the fix

Run the smallest reproducible command first, then retry the agent task only after authentication, quota, and tool discovery are stable.

wrangler --version
wrangler secret list
wrangler deploy --dry-run

Related errors

Related tools

Sources

Based on common developer troubleshooting patterns and linked EasyTool references.