Cloudflare · infra · fg-0213

process.env is empty in a Cloudflare Worker while env.MY_VAR works inside fetch

If you see process.env.API_KEY is undefined in a deployed Worker, the cause and the fix for Cloudflare are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
process.env.API_KEY is undefined in a deployed WorkerReferenceError: process is not definedLibraries that read process.env at import time get no config
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"]
Affected
Cloudflare Workers, process.env population default on for compatibility_date 2025-04-01 or later with nodejs_compat
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