resend / react-email

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

Errors while importing Email template in Node #812

Open moizkamran opened 1 year ago

moizkamran commented 1 year ago

Describe the Bug

Bug Description

I am facing an issue while integrating the email functionality using @react-email/render and nodemailer packages. The code crashes with an "ERR_MODULE_NOT_FOUND" error.

Actual Behavior

The code crashes with an "ERR_MODULE_NOT_FOUND" error. The error message indicates that a specific module is not found. Error: module not found at ... ...

Environment

Additional Information

// Code snippet or relevant configurations
import User from '../schemas/User.schema.js';
import { Email } from '../emails/email';
import { render } from '@react-email/render';

const userRoute = async (fastify) => {

    const giftHTML = render(Email);

    fastify.post('/', async (request, reply) => {
        try {
            const userData = request.body

            // Create a new user object based on the received data
            const user = new User(userData)

Which package is affected (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://react.email/docs/integrations/nodemailer#3-convert-to-html-and-send-email

To Reproduce

Steps to Reproduce

  1. Install dependencies: @react-email/render and nodemailer.
  2. Create an email template using React in a .jsx or .tsx file.
  3. Import the email template, convert it to HTML, and send the email using Nodemailer.
  4. Execute the code and observe the crash with the "ERR_MODULE_NOT_FOUND" error.

Expected Behavior

Expected Behavior

This is what react-email says on their docs to convert emails into html with node js

image

``

What's your node version? (if relevant)

No response

liydaco commented 1 year ago

Same issue, node v 18.14.0

joaopcm commented 7 months ago

Hey! I'm facing the same issue! Is there any update on this?

gabrielmfern commented 7 months ago

Hey @joaopcm, since you were the last one to comment here, could you make a minimal reproduction repo of this?

joaopcm commented 7 months ago

Hey @joaopcm, since you were the last one to comment here, could you make a minimal reproduction repo of this?

Hey, @gabrielmfern! Thank you for reminding me I left this comment in this thread! I found the solution and shared it here. My issue was more about supporting React.js components in a Node.js environment using a NestJS project.

Nithishprem commented 6 months ago

Hey, I am also difficulty in using react-email components in nodejs server. Is it possible to import react-email components in express sever to send emails?

joaopcm commented 6 months ago

Hey, I am also difficulty in using react-email components in nodejs server. Is it possible to import react-email components in express sever to send emails?

Hey, @Nithishprem! I believe I had a similar issue. I was using NestJS (which uses Express as the main API engine) with TypeScript. As I'm using SWC to build my project, I needed to add the proper configurations to support JSX/TSX files when compiling the project. Have you already tried something similar to this?

shon-morgun commented 6 months ago

same issue node v18.17.0

LockeandDropit commented 5 months ago

Hey @joaopcm!

Both links you provided redirect to a twitter (X) post that doesn't have any comments or solutions present. Were you able to find a solution to the above issue? I have been stuck on it for longer than I care to admit 😅

joaopcm commented 5 months ago

Hey @joaopcm!

Both links you provided redirect to a twitter (X) post that doesn't have any comments or solutions present. Were you able to find a solution to the above issue? I have been stuck on it for longer than I care to admit 😅

@LockeandDropit, this is what I see when I open the X link ↓

CleanShot 2024-05-28 at 4  06 01@2x

gusmagnago commented 3 months ago

No able to find the solution, I have tried so many things already and nothing could make it work properly...

gabrielmfern commented 3 months ago

@gusmagnago Could you make a reproduction of it? Seems to me that everyone having this issue here is having it for different reasons.

It could be that you might have something misconfigured, as @joaopcm did.

basememara commented 1 month ago

We're having issues too getting our NestJS backend to use React Email to send out emails.

gabrielmfern commented 1 month ago

@basememara Would you be willing to share a minimal reproduction of it? With one I can help you for sure.