Error: do not use legacy react-dom/server APIs #1143
Replies: 11 comments 1 reply
-
Can you try adding |
Beta Was this translation helpful? Give feedback.
-
I didn't understood - please be more specific |
Beta Was this translation helpful? Give feedback.
-
I mean for you to add |
Beta Was this translation helpful? Give feedback.
-
Thank you for shared example Is render in project work? |
Beta Was this translation helpful? Give feedback.
-
I see, now looking at the full error the actual solution is TL;DR you need to use This happens because Next overrides the legacy APIs for rendering (which we use for the default render still) and throws an error so that they do not use it internally. What you can do here is call |
Beta Was this translation helpful? Give feedback.
-
I think this issue can only really be fixed once we remove |
Beta Was this translation helpful? Give feedback.
-
I tried to use Error I'm message about
I commited changes to minimal example so you make sute that I have const emailMessageString = renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
}) in I tried to clear Fiximport { renderAsync } from "@react-email/render"
import CheckEmail from "./emails/CheckEmail"
import { formatDeliveryDate } from "./utils/formatDeliveryDate"
export default async function Home() {
const deliveryDate = formatDeliveryDate()
const emailMessageString = renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
})
return <div>hi</div>
} I added async to function i fire const emailMessageString = renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
}) Should be in async function to get it work without errors QuestionIf I trun code to this "use client"
import { renderAsync } from "@react-email/render"
import CheckEmail from "./emails/CheckEmail"
import { formatDeliveryDate } from "./utils/formatDeliveryDate"
import { useEffect, useState } from "react"
export default function Home() {
const deliveryDate = formatDeliveryDate()
const [emailMessageString, setEmailMessageString] = useState("")
useEffect(() => {
async function renderEmail() {
const emailMessageString = await renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
})
setEmailMessageString(emailMessageString)
}
renderEmail()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
console.log(18, "emailMessageString - ", emailMessageString)
return <div>{emailMessageString}</div>
} I'm still getting error - how to fix error? |
Beta Was this translation helpful? Give feedback.
-
Using renderAsync did fix the issue, but you still need to upgrade @react-email/tailwind as well because it also used to have renderToStaticMarkup inside. Though I think you will need to upgrade @react-email/tailwind to canary as well |
Beta Was this translation helpful? Give feedback.
-
After updating @react-email/tailwind to canary verstion - issue persists package.json "@react-email/tailwind": "0.0.14-canary.0", Code "use client"
import { renderAsync } from "@react-email/render"
import CheckEmail from "./emails/CheckEmail"
import { formatDeliveryDate } from "./utils/formatDeliveryDate"
import { useEffect, useState } from "react"
export default function Home() {
const deliveryDate = formatDeliveryDate()
const [emailMessageString, setEmailMessageString] = useState("")
useEffect(() => {
async function renderEmail() {
const emailMessageString = await renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
})
setEmailMessageString(emailMessageString)
}
renderEmail()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
console.log(18, "emailMessageString - ", emailMessageString)
return <div>{emailMessageString}</div>
} |
Beta Was this translation helpful? Give feedback.
-
@nicitaacom This is because you haven't changed from where you are importing Tailwind on the email, |
Beta Was this translation helpful? Give feedback.
-
SolvedSteps to solve this issue:
"@react-email/render": "0.0.11-canary.0",
"@react-email/tailwind": "0.0.14-canary.0",
"use client"
import { renderAsync } from "@react-email/render"
import CheckEmail from "./emails/CheckEmail"
import { formatDeliveryDate } from "./utils/formatDeliveryDate"
import { useEffect, useState } from "react"
export default function Home() {
const deliveryDate = formatDeliveryDate()
const [emailMessageString, setEmailMessageString] = useState("")
useEffect(() => {
async function renderEmail() {
const emailMessageString = await renderAsync(<CheckEmail deliveryDate={deliveryDate} />, {
pretty: true,
})
setEmailMessageString(emailMessageString)
}
renderEmail()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
console.log(18, "emailMessageString - ", emailMessageString)
return <div>{emailMessageString}</div>
}
import {
Head,
Html,
Preview,
Body,
Container,
Section,
Img,
Heading,
Text,
Column,
Link,
} from "@react-email/components"
import { Tailwind } from "@react-email/tailwind"
import CheckEmail from "@/emails/CheckEmail"
import { resend } from "@/libs/resend"
import { NextResponse } from "next/server"
export type TAPISendEmail = {
from: string
to: string
subject: string
html: string
}
export async function POST(req: Request) {
const { from, to, subject,html } = (await req.json()) as TAPISendEmail
try {
const response = await resend.emails.send({
from: from,
to: to,
subject: subject,
html: html
})
console.log(22, "response - ", response)
return NextResponse.json({ status: 200 })
} catch (error) {
if (error instanceof Error) {
console.log(29, "SEND_EMAIL_ERROR\n \n", error.message)
return new NextResponse(`/api/send-email/route.ts error \n ${error}`, {
status: 500,
})
}
}
} And import { Resend } from "resend"
export const resend = new Resend(process.env.NEXT_RESEND_SECRET) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Bug
I got this error
Which package is affected (leave empty if unsure)
@react-email/render
Link to the code that reproduces this issue
https://github.com/nicitaacom/acc2-send-email-react-email-resend
To Reproduce
To Reproduce
git clone https://github.com/nicitaacom/acc2-send-email-react-email-resend
pnpm i
pnpm dev
Expected Behavior
I see error
Might be related
vercel/next.js#57669
vercel/next.js#58305
vercel/next.js#59441
I found no solution there that's why I created this issue
I use Next + TypeScript + Tailwind + react-email + resend
So this issue might be related to react-email as well
I asked chatGPT
You can rewrite the import statement in the file where you are using the react-email package. Look for the file where you have the import statement for @react-email/render and replace the import as follows:
I didn't understood where should I change these lines
Beta Was this translation helpful? Give feedback.
All reactions