resend-node: Passing the React email component into the react property throws an error during the next build.
Using the latest Next.js 14.0.1 and resend 2.0.0-canary.2 throws an error when passing the React email template component the react property inside the resend.emails.send function.
Failed to compile.
./node_modules/html-to-text/lib/html-to-text.mjs + 24 modules
Cannot get final name for export 'encodeXML' of ./node_modules/entities/lib/esm/index.js
> Build failed because of webpack errors
Creating an optimized production build
This doesn’t work:
export const sendQuotationEmail = async (formData: FormInputs) => {
const result = QuotationFormSchema.safeParse(formData);
let data;
if (result.success) {
const { name, email, phone, website, service, message } = result.data;
try {
data = await resend.emails.send({
from:
process.env.EMAIL_FROM_ADDRESS ||
"Contact Form <onboarding@resend.dev>",
to: process.env.EMAIL_TO_ADDRESS || "",
subject: "Message from quotation form",
reply_to: email,
react: QuotationFormEmail({
name,
email,
phone,
website,
service,
message,
}),
});
} catch (error: unknown) {
console.log(error);
}
}
};
This works:
import { renderAsync } from "@react-email/render";
export const sendQuotationEmail = async (formData: FormInputs) => {
const result = QuotationFormSchema.safeParse(formData);
let data;
if (result.success) {
const { name, email, phone, website, service, message } = result.data;
const html = await renderAsync(
QuotationFormEmail({
name,
email,
phone,
website,
service,
message,
}) as React.ReactElement,
);
try {
data = await resend.emails.send({
from:
process.env.EMAIL_FROM_ADDRESS ||
"Contact Form <onboarding@resend.dev>",
to: process.env.EMAIL_TO_ADDRESS || "",
subject: "Message from quotation form",
reply_to: email,
html: html,
});
} catch (error: unknown) {
console.log(error);
}
}
};
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Add patch fix https://github.com/resendlabs/resend-node/issues/256 — committed to dubinc/dub by steven-tey 3 years ago
- Attempt patch: renderAsync: https://github.com/resend/resend-node/issues/256 — committed to s1xp4c/frigear-sub-payments by s1xp4c 3 years ago
Can confirm this is also happening for me. I’m on
Next 14.0.1and resend2.0.0Using
renderAsyncas the OP mentioned is the workaround. Mysendmethod is nothing special:Passing react did work locally but fails on build and receive the
encodeXMLerror. It builds fine when usinghtmlusing therenderAsyncpart.facing the same error as well – thought it was an issue with
@react-email/render, but looks like it’s an issue withresenditselfI was running into the same error when building my Next.js project:
Error
Solution
To fix this, you need to replace the consolidated react-email component imports with individual ones:
Before ❌
After ✅
Explanation
The consolidated
@react-email/componentspackage seems to have issues with webpack’s module resolution, specifically with the entities package’s ESM exports. By importing each component directly from its dedicated package, we avoid these resolution issues while maintaining the same functionality.Additional Notes
If you’re using additional components like Column, Row, or Tailwind (e.g. because you’re using a different react-email template), you’ll need to install and import those separately as well.
Install
and import in your code: