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

EmailProvider + nodemailer fails with Vercel Edge Runtime due to Node.js 'stream' dependency #8357

Closed
madhurjain opened this issue Aug 19, 2023 · 10 comments
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@madhurjain
Copy link

Environment

System:
OS: Linux 5.19 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (4) x64 Intel(R) Core(TM) i7-10600U CPU @ 2.80GHz
Memory: 1.86 GB / 16.00 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
pnpm: 8.6.10 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: 108.0.5359.124

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

Due to nodemailer's dependency on Node.js 'stream' module, it doesn't work with vercel's edge runtime.
Since EmailProvider has nodemailer as peer dependency importing it in a route marked as edge runtime throws below error -

The edge runtime does not support Node.js 'stream' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

https://nextjs.org/docs/messages/node-module-in-edge-runtime

How to reproduce

  • In a Next.js 13.4 project, install Auth.js and peer dependency nodemailer
  • Import EmailProvider in a route.ts that's marked as edge runtime using export const runtime = 'edge'
  • Build NextJS project using pnpm run build

Expected behavior

Decouple EmailProvider and nodemailer so it doesn't throw an error

@madhurjain madhurjain added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Aug 19, 2023
@madhurjain
Copy link
Author

Tried raising an issue with nodemailer thinking stream was the only dependency causing this issue but it was closed saying -

Edge functions only work with front end modules. 
None of the backend Node apis that Nodemailer requires and can’t function without are supported there.

nodemailer/nodemailer#1563 (comment)

Given this, can nodemailer be made a soft-dependency to Auth.js?

@madhurjain
Copy link
Author

For now, I can probably use HTTP-based Email Provider to get around the issue

https://authjs.dev/guides/providers/email-http

@balazsorban44
Copy link
Member

This is expected. nodemailer - as the name suggests - is a Node.js-focused library. You can see alternatives above via the http-based email provider guide

@codinginflow
Copy link

codinginflow commented Apr 17, 2024

The link to the HTTP email provider leads to 404. Are the updated guides on this?

@fristyr
Copy link

fristyr commented Jul 4, 2024

Why this was closed @balazsorban44 ? Maybe documentation needs to be updated at least ? It's kinda weird when you see nodemailer there with next.js, but when you try it you see the error

@brandonfake69
Copy link

Yes, this should be reopened. Given that in the docs you explicitly support nodemailer.

@iAmKrug
Copy link

iAmKrug commented Jul 14, 2024

Yes, this should be reopened. Given that in the docs you explicitly support nodemailer.

Agreed, this should be reopened. Following the official Email Provider docs for Nodemailer and next.js it produces the same error:

https://authjs.dev/getting-started/authentication/email

Error: The edge runtime does not support Node.js 'stream' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

@SaltyRain
Copy link

so basically nodemailer cannot be used in any nextjs apps + nextauth? That's kind of weird while by default nextjs uses nodejs runtime. Or am I missing something?

@martinappo
Copy link

martinappo commented Aug 14, 2024

This seems to be exactly the case of edge-compatibility.

In the current state of next-auth-example repository, middleware.ts imports the NextAuth object from auth.ts, but middleware is run in edge environment.

Nodemailer is not edge-compatible library, so you have to split up the configuration and use only edge-compatible parts in edge environments (such as middleware).

Just follow the example in given link and avoid using Nodemailer provider in edge environments.


But I think it is not necessary to reopen this, the email provider documentation doesn't necessarily state that it will work with next-auth-example nor the next-auth-example uses the Nodemailer provider. Additionally, there is an explicit documentation available describing edge compatibility, that covers the problem in this issue.

@csyedbilal
Copy link

1+ same issue i'm facing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

9 participants