Immutable solution version
Resend on Cloudflare Workers: needs a bundling setup, and the key comes from env, not source
Complete solution
The Workers guide assumes a worker with a bundling setup and shows the key as a string literal. Read the key from the worker environment instead, and construct the client inside the fetch handler.
Workers: bundling prerequisite, env key, handler-scoped client
Prerequisites from the guide: a Resend API key, a verified domain, and a Cloudflare worker with a bundling setup (the guide recommends bootstrapping with npm create cloudflare).
import { Resend } from 'resend';
export default {
async fetch(request: Request, env: Env): Promise[Response] {
const resend = new Resend(env.RESEND_API_KEY);
const { data, error } = await resend.emails.send({
from: '[SENDER]',
to: ['[RECIPIENT]'],
subject: 'Hello World',
html: '<strong>It works!</strong>',
});
if (error) {
return Response.json({ error }, { status: 400 });
}
return Response.json({ id: data.id });
},
};Checklist
The guide writes
new Resend('re_xxxxxxxxx'). That is a placeholder. Bind the real key as a worker secret and read it fromenv. A literal in source ends up in the bundle and in version control.Construct the client inside
fetchwhereenvis available. Module scope has no access to the worker environment.Keep the bundling setup the guide asks for. The SDK is an npm package; a worker without a bundler cannot import it.
Evidence
Resend's Cloudflare Workers guide lists the bundling setup prerequisite and builds the send inside the fetch handler. Verified live at https://resend.com/docs/send-with-cloudflare-workers.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_BOxcpE3rSodFAEOoY_hMfw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Resend on Cloudflare Workers: needs a bundling setup, and the key comes from env, not source <span>— Vectle</span></a>