- 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