Open jonasb opened 11 months ago
It works as well if I run it with --remote
: npx wrangler dev --remote
Hey! ๐ Thanks for raising this. Agree importing cloudflare:email
probably shouldn't throw. Logging seems like a nice simple solution too. Will get this added to the backlog. ๐
If someone needs a workaround; This works fine for me.
if (env.MAIL_ACTIVE === 'false') {
console.log(`Sending mail to ${mail.to} with subject ${mail.subject}`)
console.log(mail.body);
return;
}
const cfMail = await import('cloudflare:email');
const email = new cfMail.EmailMessage(env.MAIL_FROM, mail.to, msg.asRaw());
What does the error message mean? If it is telling me that the email binding is not available in local development, shouldn't that just be a [WARNING]
?
โ [ERROR] service core:user:REDACTED-PROJECT-NAME: Uncaught Error: No such module "cloudflare-internal:email".
imported from "cloudflare:email"
The --remote
option does not work:
C:\work\src\still-wave-a176>yarn run start --remote
yarn run v1.22.22
$ wrangler dev --remote
โ
๏ธ wrangler 3.53.1
-------------------
โฒ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
[wrangler:inf] Ready on http://127.0.0.1:8787
โ [ERROR] Error while creating remote dev session: TypeError: fetch failed
at fetch (C:\work\src\still-wave-a176\node_modules\wrangler\wrangler-dist\cli.js:17033:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async createPreviewSession
(C:\work\src\still-wave-a176\node_modules\wrangler\wrangler-dist\cli.js:202569:28)
at async start
(C:\work\src\still-wave-a176\node_modules\wrangler\wrangler-dist\cli.js:203154:9) {
cause: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}
node --version v21.7.1
BTW: this doc example reply email worker does not work https://developers.cloudflare.com/email-routing/email-workers/reply-email-workers/
This is still throwing error in Wrangler 3.72.2, any solution?
Uncaught Error: No such module "cloudflare-internal:email".
imported from "cloudflare:email"
Hello Guys, me I have instead the following error when trying to use cloudflare:email inside my worker. Should I understand that I cannot use it inside the worker directly ? I am using wrangler 3.72.2
X [ERROR] Could not resolve "cloudflare:email"
src/services/sendReports.ts:23:32:
23 โ const cfMail = await import('cloudflare:email');
โต ~~~~~~~~~~~~~~~~~~
You can mark the path "cloudflare:email" as external to exclude it from the bundle, which will
remove this error. You can also add ".catch()" here to handle this failure at run-time instead of
bundle-time.```
@Jk3ndo How to mark external?
Sorry for late reply @vickyRathee .. Indeed I have marked it as external and it worked. Now it depends on your bundler. For vite.js you can do the following and the issue should be solved.
export default {
build: {
rollupOptions: {
external: ['cloudflare:email'],
},
},
};
@Jk3ndo i build with wrangler
wrangler pages ./public โkv=CACHE โd1=testdb
Any advice on how one get to test the flow of emails in development with pages (in a sveltekit project?) Documentation seems very basic on this topic. Does not seem like it is design for pages, or am I missing something?
Normally there is a variety of factors that would make up an email to be send. Is this the tool for that or do we are we suppose to use something external. Can cloudflare please comment on that?
@Jk3ndo i build with wrangler
wrangler pages ./public โkv=CACHE โd1=testdb
Hello @vickyRathee , I am sorry but I can't help since I never did it like. But I will check and let you know if I find a way.
Any advice on how one get to test the flow of emails in development with pages (in a sveltekit project?) Documentation seems very basic on this topic. Does not seem like it is design for pages, or am I missing something?
Normally there is a variety of factors that would make up an email to be send. Is this the tool for that or do we are we suppose to use something external. Can cloudflare please comment on that?
In case someone else passes by with this problem. My solution was to singup with https://resend.com/ and 10 minutes later I had my mail delivered. Quicker than trying to find out how this works.
Describe the solution
When adding
import { EmailMessage } from 'cloudflare:email';
toindex.ts
(following the docs) I get the following error when runningwrangler dev
:I don't need to send emails locally but it would be nice if I could at least run my project locally. Maybe if Miniflare just writes a log message when I try to send an email?