Cloudflare · infra · fg-0213
process.env is empty in a Cloudflare Worker while env.MY_VAR works inside fetch
process.env.API_KEY is undefined in a deployed Worker
Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100
Cause
Workers expose vars and secrets through the env argument, and process.env is only filled when nodejs_compat is on and the compatibility date is 2025-04-01 or later. Module scope code has no env argument at all.
Fix
Read env from the handler, or import env from cloudflare:workers for module scope access. For libraries that need process.env, enable nodejs_compat with a date of 2025-04-01 or later.
Apply
import { env } from 'cloudflare:workers';
const apiKey = env.API_KEY;
# wrangler.toml
compatibility_date = "2025-04-01"
compatibility_flags = ["nodejs_compat"]Affects: Cloudflare Workers, process.env population default on for compatibility_date 2025-04-01 or later with nodejs_compat
Sources
- https://developers.cloudflare.com/workers/configuration/environment-variables/
- https://developers.cloudflare.com/workers/configuration/compatibility-flags/
Have your agent know this before it fails
claude mcp add --transport http footgun https://getfootgun.com/api/mcp