resend / react-email

💌 Build and send emails using React
https://react.email
MIT License
14.28k stars 652 forks source link

Cannot render email | TypeError: undefined is not an object (evaluating 'Object.hasOwn(Z,"renderToReadableStream")') #1745

Open amjed-ali-k opened 1 day ago

amjed-ali-k commented 1 day ago

Describe the Bug

I am getting this error when sending email from bun@latest.

TypeError: undefined is not an object (evaluating 'Object.hasOwn(Z,"renderToReadableStream")')
at hasOwn (native:1:1)
at /node_modules/@react-email/render/dist/node/index.mjs:99:14
at G (/node_modules/@react-email/render/dist/node/index.mjs:21:24) 
at processTicksAndRejections (native:7:39) 

My code sample


import * as React from "react";
import { render } from "@react-email/render";
import { Resend } from "resend";
import MedTravelBooking, {
  MedTravelBookingSubject,
  MedtravelProps,
} from "./emails/medtravel-submission";

export async function sendMedtravelEmailToAdmin(
  email: string,
  data: MedtravelProps,
): Promise<any> {
  try {
    await resend.emails.send({
      from: FROM_EMAIL,
      to: email,
      subject: MedTravelBookingSubject,
      html: await render(<MedTravelBooking data={data} />, {
        pretty: true,
      }),
    });
  } catch (error) {
    console.error(error);
  }
  return true;
}

Which package is affected (leave empty if unsure)

@react-email/render

Link to the code that reproduces this issue

-

To Reproduce


import * as React from "react";
import { render } from "@react-email/render";
import { Resend } from "resend";
import MedTravelBooking, {
  MedTravelBookingSubject,
  MedtravelProps,
} from "./emails/medtravel-submission";

export async function sendMedtravelEmailToAdmin(
  email: string,
  data: MedtravelProps,
): Promise<any> {
  try {
    await resend.emails.send({
      from: FROM_EMAIL,
      to: email,
      subject: MedTravelBookingSubject,
      html: await render(<MedTravelBooking data={data} />, {
        pretty: true,
      }),
    });
  } catch (error) {
    console.error(error);
  }
  return true;
}

Expected Behavior

--

What's your node version? (if relevant)

No response

doepnern commented 1 day ago

Have been having the same problem in Bun. Downgrading @react-email/components to 0.0.20 fixed the problem for me. Seems to have been introduced at some point after that.

gabrielmfern commented 23 hours ago

Tried it myself on a blank project that just plain console logs a simple email rendered and got no error. Can you share a minimal repo that reproduces the error? @amjed-ali-k

amjed-ali-k commented 23 hours ago

I got this error only in production, which is running on an Ubuntu VPS. Also i bundled and minified entire code into a single file using bun bundler.

Will provide more details and minimal repo shortly.

doepnern commented 22 hours ago

I couldn't reproduce it locally either, happened in the oven/bun:2.0.0 docker image for me (build and then running the compiled js locally also didn't trigger the error)

1finedev commented 11 hours ago

+1 on this, getting same error on bun, ubuntu vps

Screenshot 2024-10-26 at 05 33 45
1finedev commented 10 hours ago

after a bit of research bun add react@canary react-dom@canary seems to fix my issue

Bun Guide

amjed-ali-k commented 8 hours ago

Reproduction of this issue.

@gabrielmfern You can find the reprod here. Run bundled version using bun run start and it will throw the error. https://github.com/amjed-ali-k/react-email-bun-bundler-bug

here is the screenshot image