#Help: env.RESEND_API_KEY is undefined in my Worker despite being configured as a Secret

1 messages · Page 1 of 1 (latest)

fossil rain
#

I'm encountering a very frustrating issue with my Cloudflare Worker and hoping someone might have some insight.

The problem is: My Worker (luisminutri-email-handler) is failing because an environment variable (RESEND_API_KEY), which is configured as a "Secret" in the Worker settings, consistently comes back as undefined at runtime.

Key details:

Worker Name: luisminutri-email-handler
Worker URL: https://luisminutri-email-handler.masterkhro.workers.dev/

Error in Worker console logs: Worker Error: 'env' object or RESEND_API_KEY is undefined. Check Worker settings.
Configuration: The RESEND_API_KEY variable is explicitly set as "Secret" under "Settings" -> "Variables and Secrets", showing "Value encrypted".
Relevant Code: I access the variable via env.RESEND_API_KEY inside handleRequest(request, env).
Steps already taken:

Verified the variable configuration as "Secret" and confirmed the name is correct.
Recreated the Worker from scratch (deleted and created a new one).
Reviewed code syntax, which is plain JavaScript.
Verified CORS headers (the 500 is due to the missing key, not CORS).
Cloudflare documentation states there's no difference for the Worker between a regular variable and a secret.
Has anyone encountered a similar issue where "Secrets" are not correctly injected into the env object despite being properly configured? Are there any known limitations for Free accounts or an additional debugging step I should consider?

Any help or suggestions would be greatly appreciated! Thanks in advance!

fossil rain
#

No one has an idea? ☹️

glossy pier
#

Can you share your worker code which used the environment variable?

fossil rain
#

There is the code @glossy pier

#

Thanks in advance

glossy pier
fossil rain
#

I'm going to follow your suggestions, modify my code and test if I can make it work. Big Thanks!!!