backpack1098B
Convex Community3y ago
36 replies
backpack1098

Uncaught Failed to analyze email/emailClient.js: Unexpected token '<'

hello team. sorry to keep bugging y'all. im running into
400 Bad Request: InvalidModules: Hit an error while pushing:
Loading the pushed modules encountered the following
    error:
Uncaught Failed to analyze emailClient.js: Unexpected token '<'

here's the code
"use node"

import { createElement } from "react"
import { v } from "convex/values"
import { Resend } from "resend"

import { internalAction } from "../_generated/server"
import ResendExampleTemplate from "../../react-email-starter/emails/resendExampleTemplate"

export const sendEmail = internalAction({
  args: {
    to: v.string(),
    subject: v.string(),
  },
  handler: async (ctx, { to, subject }) => {
    const emailTemplate = createElement(ResendExampleTemplate)

    let message = {
      from: "onboarding@resend.dev",
      subject,
      to,
    }

    if (process.env.NODE_ENV === "development") {
      console.log("local email template: ", emailTemplate)
    } else {
      const resend = new Resend(process.env.RESEND_API_KEY)
      return resend.emails.send({ ...message, react: emailTemplate })
    }
  },
})

i am currently installing the Resend module outside of the convex/ dir. (i cannot install this inside the convex/ dir since it would contain another node_modules folder). installing the Resend module outside of the convex/ dir allows me to run email dev --port 3001 to look at the email previews based on the guide: https://react.email/docs/getting-started/manual-setup.

naturally i'd be doing
import ResendExampleTemplate from "../../react-email-starter/emails/resendExampleTemplate"

in the convex/emailClient.ts to import the template. alternatively i can just copy paste the files over from the react-email-starter/ folder to the convex/templates/ folder and do
// emailClient.ts
import ResendExampleTemplate from "./templates/resendExampleTemplate"

what do y'all think?
Was this page helpful?