Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade of next@14.0.0 #989

Closed
martinez-hugo opened this issue Oct 27, 2023 · 32 comments · Fixed by #1009
Closed

Upgrade of next@14.0.0 #989

martinez-hugo opened this issue Oct 27, 2023 · 32 comments · Fixed by #1009
Labels
Type: Bug Confirmed bug

Comments

@martinez-hugo
Copy link

Describe the Bug

Hello !

I've just update my project to Next v14 but I had this error generated by upgrading :

Failed to compile.
--
08:53:51.047 |  
08:53:51.047 | ./node_modules/@react-email/render/dist/index.mjs
08:53:51.048 | Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').
08:53:51.048 |  
08:53:51.048 | Import trace for requested module:
08:53:51.048 | ./node_modules/@react-email/render/dist/index.mjs
08:53:51.048 | ./node_modules/resend/build/src/resend.js
08:53:51.048 | ./node_modules/resend/build/src/index.js
08:53:51.048 | ./src/app/api/send/route.tsx

Do you think that you can fix this error on your package ?

Thanks for all

Which package is affected (leave empty if unsure)

@react-email/render

Link to the code that reproduces this issue

  1. Upgrading of Next from 13.5 to 14.0

To Reproduce

  1. Upgrading of Next from 13.5 to 14.0

Expected Behavior

Ability to upgrading to Next 14.0 without error

What's your node version? (if relevant)

21

@martinez-hugo martinez-hugo added the Type: Bug Confirmed bug label Oct 27, 2023
@Jordaneisenburger
Copy link

Jordaneisenburger commented Oct 27, 2023

also happens for me on Node 18.17.0

@adrianfabjanski
Copy link

Same issue here Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream'). after upgrading to next 14.0

@marlon12796
Copy link

Does anyone know a solution?

@adrianfabjanski
Copy link

Does anyone know a solution?

rollback to 13.5 😢

@bukinoshita
Copy link
Member

Let's address this issue ASAP to unblock people.

@juanmagalhaes
Copy link

Yeah, same story here. 😅

@Melvynx
Copy link

Melvynx commented Oct 28, 2023

Yeah, same error here. react-emails doesnot work with NextJS !

@rvanlaarhoven
Copy link

Duplicate of #868, including some possible workarounds for now

@jlison
Copy link

jlison commented Oct 29, 2023

If you're encountering challenges following an upgrade to Next.js 14, here's how I successfully worked around the issue: #868 (comment)

@bukinoshita
Copy link
Member

Are you guys using something like this?

import { render } from '@react-email/render';
import { MyEmail } from '../../../emails/my-email';
import { NextResponse } from 'next/server';

export const runtime = 'edge'

export const GET = async () => {
  const html = await render(MyEmail());
  return NextResponse.json({ html }, { status: 200 })
}

@niels-bosman
Copy link
Contributor

niels-bosman commented Oct 30, 2023

@bukinoshita I am using it in conjunction with next-auth to send one time login link emails.

/app/api/auth/[...nextauth]/route.ts

import NextAuth from 'next-auth';
import { PrismaAdapter } from '@auth/prisma-adapter';
import { render } from '@react-email/render';
import { sendgridBaseOptions, sendgridClient } from '@/utils/sendgrid';
import { LoginMagicLink } from '../../../../../emails/login';
import prisma from '../../../../../lib/prisma';

type VerificationRequest = {
  identifier: string;
  url: string;
};

export const authOptions: any = {
  adapter: PrismaAdapter(prisma),
  providers: [
    {
      id: 'sendgrid',
      type: 'email',
      async sendVerificationRequest({ identifier, url }: VerificationRequest) {
        const emailHtml = render(LoginMagicLink({ url })); // <-------- react-email creation

        const options = {
          ...sendgridBaseOptions,
          subject: 'Welcome! Here is your login link.',
          html: emailHtml,
        };

        await sendgridClient.send({ ...options, to: identifier });
      },
    },
  ],
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

@bukinoshita
Copy link
Member

@niels-bosman

Can you try using the canary version of render to see if this is still happening?

{
  ...,
  "@react-email/render": "0.0.9-canary.0",
}

@mrtom
Copy link

mrtom commented Oct 30, 2023

I am having the same issue as @niels-bosman, trying to send a verification request in next-auth.

Trying the canary now

@mrtom
Copy link

mrtom commented Oct 30, 2023

Unfortunately no changes:

git:(upgrade-next) ✗ npm run dev
Debugger attached.

> dev
> next dev -p 3001 && yarn bootstrap:emails

Debugger attached.
Debugger attached.
   ▲ Next.js 14.0.0
   - Local:        http://localhost:3001
   - Environments: .env.development.local, .env

Debugger attached.
Waiting for the debugger to disconnect...
 ✓ Ready in 3s
 ○ Compiling /page ...
 ⨯ ./react-email-starter/node_modules/@react-email/render/dist/index.mjs
Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').

Import trace for requested module:
./react-email-starter/node_modules/@react-email/render/dist/index.mjs
./react-email-starter/node_modules/@react-email/components/dist/index.mjs
./react-email-starter/emails/magicSignInLink.tsx
./src/lib/email/authVerification.ts
./pages/api/auth/[...nextauth].ts
./app/authProvider.tsx
./app/layout.tsx
 ⨯ ./react-email-starter/node_modules/@react-email/render/dist/index.mjs
Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').

Import trace for requested module:
./react-email-starter/node_modules/@react-email/render/dist/index.mjs
./react-email-starter/node_modules/@react-email/components/dist/index.mjs
./react-email-starter/emails/magicSignInLink.tsx
./src/lib/email/authVerification.ts
./pages/api/auth/[...nextauth].ts
./app/page.tsx
 ⨯ ./react-email-starter/node_modules/@react-email/render/dist/index.mjs
Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').

Import trace for requested module:
./react-email-starter/node_modules/@react-email/render/dist/index.mjs
./react-email-starter/node_modules/@react-email/components/dist/index.mjs
./react-email-starter/emails/magicSignInLink.tsx
./src/lib/email/authVerification.ts
./pages/api/auth/[...nextauth].ts
./app/page.tsx
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.

From my yarn.lock:


"@react-email/preview@0.0.7":
  version "0.0.7"
  resolved "https://registry.yarnpkg.com/@react-email/preview/-/preview-0.0.7.tgz#8d1c9fd27ba45f0449ef6e35484c94da5a6a0de5"
  integrity sha512-YLfIwHdexPi8IgP1pSuVXdAmKzMQ8ctCCLEjkMttT2vkSFqT6m/e6UFWK2l30rKm2dDsLvQyEvo923mPXjnNzg==

"@react-email/render@0.0.8":
  version "0.0.8"
  resolved "https://registry.yarnpkg.com/@react-email/render/-/render-0.0.8.tgz#4b313817835e4d106a2442cc8ee48a96a01e8631"
  integrity sha512-DwrCG5t2nXlXYcchZz8h4NOhBYoU5Rpogz54Z18mANUmwMtzl88x6NwRDwzZoAVAlTLOPqvsQbYtWHvfpTfmmA==
  dependencies:
    html-to-text "9.0.5"
    pretty "2.0.0"
    react "18.2.0"
    react-dom "18.2.0"

"@react-email/render@0.0.9-canary.0":
  version "0.0.9-canary.0"
  resolved "https://registry.yarnpkg.com/@react-email/render/-/render-0.0.9-canary.0.tgz#6270fe4717cd61818fb1fc7ce315da0b03b71e4e"
  integrity sha512-I1BjR9RiKNgqPNuUnpdDMRA9VOPmwtSWkHU2A3M+MkDZMed1ZVd5+vT6mHhVutseJvfh11jG5/hpvksyastfiw==
  dependencies:
    html-to-text "9.0.5"
    pretty "2.0.0"
    react "18.2.0"
    react-dom "18.2.0"

Which indicates I have both version of @react-email/render in my deps, but on disk:

vim node_modules/@react-email/render/package.json

Gives me

{
  "name": "@react-email/render",
  "version": "0.0.9-canary.0",
  "description": "Transform React components into HTML email templates",
...

So looks like that has upgraded properly

@niels-bosman
Copy link
Contributor

niels-bosman commented Oct 30, 2023

@bukinoshita I can confirm that the new canary version did not resolve my issues either.

Edit: shouldn't https://react.dev/reference/react-dom/server/renderToPipeableStream be used instead of renderToReadableStream?

On https://react.dev/reference/react-dom/server/renderToString#alternatives it says that the renderToPipeableStream method should be used for node environments (like what Next.js uses).

@ODreelist
Copy link

can also confirm, same error when upgrading next from 13.5.6 to 14.0.0 (no other changes)

@bukinoshita
Copy link
Member

Thanks for confirming, we're still investigating and testing

@bukinoshita
Copy link
Member

We just released a new canary version @react-email/render@0.0.9-canary.2.

here's an example on Next.js 14 app router edge

import { NextResponse } from 'next/server';
import { EmailTemplate } from '../../../components/email-template';
import { renderAsync } from '@react-email/render';

export const runtime = 'edge';

export async function GET() {
  try {
    const html = await renderAsync(
      EmailTemplate({ firstName: 'John' }) as React.ReactElement
    );
    return NextResponse.json({ html });
  } catch (error) {
    return NextResponse.json({ error });
  }
}

@Jordaneisenburger
Copy link

@bukinoshita personally I don't use it via a route handler but trigger Resend to send the email from a Server Action. I've manually installed the canary version alongside the other resend/react-email packages:

"@react-email/body": "0.0.3",
"@react-email/button": "0.0.10",
"@react-email/column": "0.0.7",
"@react-email/container": "0.0.8",
"@react-email/font": "0.0.3",
"@react-email/head": "0.0.5",
"@react-email/heading": "0.0.8",
"@react-email/html": "0.0.4",
"@react-email/img": "0.0.5",
"@react-email/link": "0.0.5",
"@react-email/preview": "0.0.6",
"@react-email/row": "0.0.5",
"@react-email/section": "0.0.9",
"@react-email/tailwind": "0.0.9",
"@react-email/text": "0.0.5",
"@react-email/render": "0.0.9-canary.2",
"react-email": "1.9.5",

I've also updated next to 14.0.1 and after a yarn install && yarn build the build still breaks.

Failed to compile.

./node_modules/resend/node_modules/@react-email/render/dist/index.mjs
Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').

Import trace for requested module:
./node_modules/resend/node_modules/@react-email/render/dist/index.mjs
./node_modules/resend/build/src/resend.js
./node_modules/resend/build/src/index.js
./src/utils/server/getResend.ts
./src/utils/server/index.ts
./src/app/(dashboard)/account/page.tsx

Hope this might help, fixing the issue.

@bukinoshita
Copy link
Member

@bukinoshita personally I don't use it via a route handler but trigger Resend to send the email from a Server Action. I've manually installed the canary version alongside the other resend/react-email packages:

"@react-email/body": "0.0.3",
"@react-email/button": "0.0.10",
"@react-email/column": "0.0.7",
"@react-email/container": "0.0.8",
"@react-email/font": "0.0.3",
"@react-email/head": "0.0.5",
"@react-email/heading": "0.0.8",
"@react-email/html": "0.0.4",
"@react-email/img": "0.0.5",
"@react-email/link": "0.0.5",
"@react-email/preview": "0.0.6",
"@react-email/row": "0.0.5",
"@react-email/section": "0.0.9",
"@react-email/tailwind": "0.0.9",
"@react-email/text": "0.0.5",
"@react-email/render": "0.0.9-canary.2",
"react-email": "1.9.5",

I've also updated next to 14.0.1 and after a yarn install && yarn build the build still breaks.

Failed to compile.

./node_modules/resend/node_modules/@react-email/render/dist/index.mjs
Attempted import error: 'renderToReadableStream' is not exported from 'react-dom/server' (imported as 'renderToReadableStream').

Import trace for requested module:
./node_modules/resend/node_modules/@react-email/render/dist/index.mjs
./node_modules/resend/build/src/resend.js
./node_modules/resend/build/src/index.js
./src/utils/server/getResend.ts
./src/utils/server/index.ts
./src/app/(dashboard)/account/page.tsx

Hope this might help, fixing the issue.

Can you follow up on the Resend issue instead? (resend/resend-node#244)
If it's possible, please share your code setup there.

We tested in these scenarios and all of them passed.

  • next-13-app-router
  • next-13-app-router-edge
  • next-13-pages-router
  • next-13-pages-router-edge
  • next-14-app-router
  • next-14-app-router-edge
  • next-14-pages-router-edge

@niels-bosman
Copy link
Contributor

@bukinoshita I created this reproduction repo to demonstrate a minimum reproduction of my issue. Simply install dependencies, run the dev script and open the page to reproduce the issue.

https://github.com/niels-bosman/next-14-react-email-reproduction-repo

@bukinoshita
Copy link
Member

@bukinoshita I created this reproduction repo to demonstrate a minimum reproduction of my issue. Simply install dependencies, run the dev script and open the page to reproduce the issue.

https://github.com/niels-bosman/next-14-react-email-reproduction-repo

Please, can you try renderAsync instead of render method?

@niels-bosman
Copy link
Contributor

@bukinoshita I created this reproduction repo to demonstrate a minimum reproduction of my issue. Simply install dependencies, run the dev script and open the page to reproduce the issue.
https://github.com/niels-bosman/next-14-react-email-reproduction-repo

Please, can you try renderAsync instead of render method?

This gives me the same exact error message unfortunately.

@bukinoshita
Copy link
Member

@bukinoshita I created this reproduction repo to demonstrate a minimum reproduction of my issue. Simply install dependencies, run the dev script and open the page to reproduce the issue.
https://github.com/niels-bosman/next-14-react-email-reproduction-repo

Please, can you try renderAsync instead of render method?

This gives me the same exact error message unfortunately.

Oh, I got it. The error you're getting is from the @react-email/components instead of @react-email/render. This is because we have the render method there, but didn't update to the canary version.

Checking the email code, you can remove these packages

  • @react-email/button
  • @react-email/html
  • @react-email/render

And install the:

  • "@react-email/components": "^0.0.11-canary.0" (this includes the other components)

In the route.ts update to import from

import { renderAsync } from "@react-email/components";

@iamvishnusankar
Copy link

@bukinoshita The canary versions (@react-email/components@canary and @react-email/render@canary) seems to have fixed the issues on next@^14.0.1.

@niels-bosman
Copy link
Contributor

niels-bosman commented Nov 1, 2023

@bukinoshita I created this reproduction repo to demonstrate a minimum reproduction of my issue. Simply install dependencies, run the dev script and open the page to reproduce the issue.
https://github.com/niels-bosman/next-14-react-email-reproduction-repo

Please, can you try renderAsync instead of render method?

This gives me the same exact error message unfortunately.

Oh, I got it. The error you're getting is from the @react-email/components instead of @react-email/render. This is because we have the render method there, but didn't update to the canary version.

Checking the email code, you can remove these packages

  • @react-email/button
  • @react-email/html
  • @react-email/render

And install the:

  • "@react-email/components": "^0.0.11-canary.0" (this includes the other components)

In the route.ts update to import from

import { renderAsync } from "@react-email/components";

Can confirm that this resolved my issue!

@zenorocha
Copy link
Collaborator

We just added support for Next 14! 🎉

To upgrade, you can bump @react-email/components@v0.0.11.

Alternatively, if you're using the render util directly, you can update to @react-email/render@v0.0.9.

@carstenblt
Copy link

The synchronous render is still broken? I am getting

Error: Internal Error: do not use legacy react-dom/server APIs. If you encountered this error, please open an issue on the Next.js repo.

when calling from

import { render } from "@react-email/components";

@DeoThemes
Copy link

How to fix it when using server actions? The code is following:

try {
      data = await resend.emails.send({
        from:  "Contact Form <onboarding@resend.dev>",
        to: process.env.EMAIL_TO_ADDRESS || "",
        subject: "Message from contact form",
        reply_to: email,
        react: ContactFormEmail({
          name: name,
          email: email,
          message: message,
        }),
      });
      return { success: true, data };
    }

@corysimmons
Copy link

Does this break Tailwind support? /preview was working with Tailwind, then I upgraded to v11 and v9, and now Tailwind classes aren't being applied.

@DeoThemes
Copy link

How to fix it when using server actions? The code is following:

try {
      data = await resend.emails.send({
        from:  "Contact Form <onboarding@resend.dev>",
        to: process.env.EMAIL_TO_ADDRESS || "",
        subject: "Message from contact form",
        reply_to: email,
        react: ContactFormEmail({
          name: name,
          email: email,
          message: message,
        }),
      });
      return { success: true, data };
    }

Solution here - resend/resend-node#256

@alienbalcorp
Copy link

alienbalcorp commented Feb 27, 2024

@bukinoshita Thanks a lot! It works for me! 🚀

#989 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.