react-email icon indicating copy to clipboard operation
react-email copied to clipboard

Errors while importing Email template in Node

Open moizkamran opened this issue 1 year ago • 12 comments

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

  • Node.js version:
  • @react-email/render version:
  • nodemailer version:

Additional Information

  • Any modifications or customizations made to the email template or code.
  • Any relevant configuration settings or environment variables used.
  • Any other details or observations that could be helpful.
// 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

moizkamran avatar Jul 13 '23 01:07 moizkamran

Same issue, node v 18.14.0

liydaco avatar Aug 04 '23 13:08 liydaco

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

joaopcm avatar Mar 22 '24 22:03 joaopcm

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

gabrielmfern avatar Mar 27 '24 11:03 gabrielmfern

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.

joaopcm avatar Mar 27 '24 15:03 joaopcm

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?

Nithishprem avatar Apr 17 '24 18:04 Nithishprem

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?

joaopcm avatar Apr 17 '24 18:04 joaopcm

same issue node v18.17.0

shon-morgun avatar Apr 28 '24 07:04 shon-morgun

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 avatar May 28 '24 18:05 LockeandDropit

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

joaopcm avatar May 28 '24 19:05 joaopcm

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

gusmagnago avatar Aug 06 '24 09:08 gusmagnago

@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.

gabrielmfern avatar Aug 06 '24 15:08 gabrielmfern

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

basememara avatar Sep 13 '24 15:09 basememara

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

gabrielmfern avatar Sep 18 '24 15:09 gabrielmfern