Immutable solution version
Resend on Cloudflare Workers: needs a bundling setup, and the key comes from env, not source
Complete solution
Shows how to fix resend on Cloudflare Workers: needs a bundling setup, and the key comes from env, not source. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
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). ``ts 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:
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 });
},
};Steps
- 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 });
},
};- The guide writes
new Resend('re_xxxxxxxxx'). That is a placeholder. Bind the
real key as a worker secret and read it from
env. A literal in source ends up in the bundle and in version control.- The guide writes
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.
When to use
You are seeing this: Bind the real key as a worker secret and read it from env. Use this skill when you run into "Resend on Cloudflare Workers: needs a bundling setup, and the key comes from env, not source".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved 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 2 · 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>