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?
5 Replies
Buffer and Stream should both be supported: https://developers.cloudflare.com/workers/runtime-apis/nodejs/#supported-nodejs-apis
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Node.js APIs available in Cloudflare Workers
✘ [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; ╵~~
node_modules/string_decoder/node_modules/safe-buffer/index.js:2:21: 2 │ var buffer = require('buffer') ╵
node_modules/mailsplit/lib/node-rewriter.js:5:26: 5 │ const Transform = require('stream').Transform; ╵
Did you enable nodejs-compat flag in wrangler config?
yes.
compatibility_flags = [ "nodejs_compat" ]
wrangler.toml
i can use mailparser and buffer-dependent libs just fine, do you have a full example?