muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
80 stars 35 forks source link

Errors in Cloudflare Workers environment with recent versions #64

Open primeare opened 7 months ago

primeare commented 7 months ago

Introduction

Cloudflare in their documentation propose to use mimetext for sending emails in their Cloudflare Workers and Cloudflare Email Workers.

The problem

Since updating to version 3.0.21 (although it could be any version after 3.0.16, as it worked previously), the library does not work natively in the Cloudflare Workers environment. By saying natively, I mean without transpiling code or enabling Node.js compatibility modes or flags.

Hotfix solution

Currently, I found two possible solutions:

  1. Use browser version of mimetext: import { createMimeMessage } from 'mimetext/browser';;
  2. Enable node_compat = true in wrangler.toml to turn on Node.js polyfills.

Error details in cloudflare/wrangler-action

Node.js version: 18.19.0 NPM version: 10.2.3

image
muratgozel commented 7 months ago

hey @primeare they look like good solutions, and i think they should be in the readme under use section. create a pr if you wish or i will soon update the readme and include this.

muratgozel commented 7 months ago

ps: i will test the the library in cloudflare worker environment later and come up with a proper solution

sannajammeh commented 4 months ago

I just use mimetext/browser for this. Worker-d runs on web standards