Parsing .EML using workers

i have tried using a variety of mail parsers with workers but since workers does not have full nodejs compatibility, i am unable to use buffer or stream etc which is used by popular libs such as mailparser. is there a workaround or a compatible lib which could do it on workers?
6 Replies
Hard@Work
Hard@Work5w ago
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Node.js APIs available in Cloudflare Workers
gulluprasad123
gulluprasad123OP4w ago
✘ [ERROR] Could not resolve "buffer"
node_modules/string_decoder/node_modules/safe-buffer/index.js:2:21: 2 │ var buffer = require('buffer') ╵ ~~ [ERROR] Could not resolve "stream"
node_modules/mailsplit/lib/node-rewriter.js:5:26: 5 │ const Transform = require('stream').Transform; ╵
~~
Maston
Maston4w ago
Did you enable nodejs-compat flag in wrangler config?
gulluprasad123
gulluprasad123OP4w ago
yes. compatibility_flags = [ "nodejs_compat" ] wrangler.toml
Maston
Maston4w ago
i can use mailparser and buffer-dependent libs just fine, do you have a full example?
gulluprasad123
gulluprasad123OP4w ago
wrangler.toml name = "email-processor" main = "src/index.js" compatibility_date = "2025-01-01" compatibility_flags = [ "nodejs_compat" ] [[r2_buckets]] binding = "EMAIL_BUCKET" bucket_name = "emails"

Did you find this page helpful?