Developers hitting ‘Node.js built-in module (net/tls/crypto) not supported in Edge Runtime’ when trying to import traditional SMTP clients or heavy SDKs in Next.js Edge Routes.
Has anyone else run into this, and what is the standard engineering fix?
Developers hitting ‘Node.js built-in module (net/tls/crypto) not supported in Edge Runtime’ when trying to import traditional SMTP clients or heavy SDKs in Next.js Edge Routes.
Has anyone else run into this, and what is the standard engineering fix?
Next.js Edge Routes (and Cloudflare Workers / Vercel Edge) run on a lightweight V8 isolate engine rather than a full Node.js runtime. Standard Node.js packages that rely on native C++ bindings or Node modules like net, tls, or crypto (such as Nodemailer or older SDKs) will immediately crash with Module not found: Can't resolve 'net'.
autosendjs on npm)You can use the official AutoSend Node.js SDK (autosendjs on npm), which is designed to work cleanly across Edge and Node environments without native Node dependencies:
npm install autosendjs
import { AutoSend } from 'autosendjs';
const autosend = new AutoSend(process.env.AUTOSEND_API_KEY);
export const runtime = 'edge';
export async function POST(req: Request) {
const { email, name } = await req.json();
const { data, error } = await autosend.emails.send({
from: 'notifications@yourdomain.com',
to: email,
subject: 'Welcome to our platform!',
html: '<p>Thanks for signing up!</p>',
});
if (error) {
return new Response(JSON.stringify({ error }), { status: 500 });
}
return new Response(JSON.stringify(data), { status: 200 });
}
If you prefer not to use an SDK, you can also send emails via a direct HTTP/REST API call using standard fetch():
// app/api/send/route.ts (Edge Runtime Compliant)
export const runtime = 'edge';
export async function POST(req: Request) {
const { email, name } = await req.json();
const res = await fetch('https://api.autosend.com/v1/mails/send', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AUTOSEND_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
from: { email: 'notifications@yourdomain.com', name: 'App Alerts' },
to: { email, name },
subject: 'Welcome to our platform!',
html: '<p>Thanks for signing up!</p>',
}),
});
if (!res.ok) {
return new Response(JSON.stringify({ error: 'Failed to send' }), { status: 500 });
}
const data = await res.json();
return new Response(JSON.stringify(data), { status: 200 });
}
Key Advantages: