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

Nodemailer doesn't work on Cloudflare Workers because it uses Built-in node modules without node: prefix #1621

Open
Aloso opened this issue Feb 9, 2024 · 7 comments

Comments

@Aloso
Copy link

Aloso commented Feb 9, 2024

Cloudflare Workers is a serverless JavaScript runtime. It has a Node.js compatibility mode, but it requires that built-in node modules are imported with the node: prefix. Because of this, Nodemailer fails to build on Cloudflare Workers.

See this blog post about the node: prefix, which is the recommended way to import built-in node modules.

Nodemailer requires the stream, fs, path, url, http, https, zlib, net, events, util, dns, child_process, os, tls, and crypto built-in modules. These should be imported with prefix, for example:

const fs = require('node:fs')
@Aloso Aloso closed this as completed Feb 9, 2024
@MickL
Copy link

MickL commented Feb 10, 2024

Hey @Aloso , why did you close this? I am also deploying on edge functions (Vercel Edge) and it does not work.

@Aloso
Copy link
Author

Aloso commented Feb 11, 2024

I figured out a better way, and I read somewhere else that smtp connections from serverless environments aren't allowed anyway. Please correct me if I'm wrong.

Since I wanted to use it for a contact form, I'm using FormSubmit now, it is very convenient and easy to set up.

@sheecegardezi
Copy link

@Aloso alternative approch still does not resolve this issue! Can you please open this issue again it. I am still unable to get it install on cloudflare worker

@Aloso Aloso reopened this Mar 30, 2024
@MickL
Copy link

MickL commented Mar 30, 2024

I think it will never run on Cloudflare, duplicate of:
#1623

Personally I switched to use Resend

@sheecegardezi
Copy link

I have reviewed all the related issues. It shouldn't be a difficult problem... SMTP seems like just another API but with its own protocol... all it needs is a JS driver to send email from Cloudflare Worker (CFW).

CFW provides an API to connect to TCP sockets which is the basic building block. The next step is to go through SMTP protocol specifications and implement the client... something like described here.

Personally, I have set up a second server on Vercel running Nodemailer.

Copy link
Contributor

github-actions bot commented May 1, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@Aloso
Copy link
Author

Aloso commented May 1, 2024

You might find this post insightful: GitHub stale bot consindered harmful

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

No branches or pull requests

3 participants