postalsys / imapflow

IMAP Client library for EmailEngine Email API (https://emailengine.app)
https://imapflow.com
Other
350 stars 59 forks source link

Cloudflare Email Worker incompatibility #193

Closed zburgermeiszter closed 4 months ago

zburgermeiszter commented 4 months ago

Describe the bug imapflow is incompatible with Cloudflare Email Workers.

➜  cloudflare-email-push-to-imap npm run start

> cloudflare-email-push-to-imap@0.0.0 start
> wrangler dev

 ⛅️ wrangler 3.52.0
-------------------
▲ [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://localhost:60385
⎔ Starting local server...
✘ [ERROR] service core:user:cloudflare-email-push-to-imap: Uncaught TypeError: util.promisify is not a function

    at null.<anonymous> (index.js:63870:37) in node_modules/imapflow/lib/proxy-connection.js
    at null.<anonymous> (index.js:12:50) in __require
    at null.<anonymous> (index.js:67431:31) in node_modules/imapflow/lib/imap-flow.js
    at null.<anonymous> (index.js:12:50) in __require
    at null.<anonymous> (index.js:69874:31)

✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

To Reproduce

  1. Generate a new worker npm create cloudflare@2.5.0 -- cloudflare-email-push-to-imap

  2. index.ts

    
    import { ImapFlow } from 'imapflow';

const client = new ImapFlow({ host: env.IMAP_HOST, port: env.IMAP_PORT, secure: true, auth: { user: env.IMAP_USER, pass: env.IMAP_PASS, }, });

export default {};


3. `wrangler.toml`

:schema node_modules/wrangler/config-schema.json

name = "cloudflare-email-push-to-imap" main = "src/index.ts" compatibility_date = "2024-04-23"

compatibility_flags = ["nodejs_compat"]

node_compat = true


5. Run the worker locally in dev mode
`npm run start`

**Expected behavior**
To be able to instantiate the ImapFlow class.

**Screenshots**
<img width="1612" alt="image" src="https://github.com/postalsys/imapflow/assets/5986229/43edaaeb-7a8b-4ade-b231-d429fa85fb22">

**Desktop (please complete the following information):**
 - OS: Mac OS Monterey 12.7.4 (Apple Silicon)
 - Runtime: Node.js
 - Version: 20.11.1
andris9 commented 4 months ago

No plans to start supporting cloudflare workers.

zburgermeiszter commented 4 months ago

No worries.

I figured out the polyfills and bundling, but it looks like as long as the net module is not allowed on CF Workers, this won't be possible.

andris9 commented 4 months ago

Cloudflare workers have an alternative for the net module, so the code can be ported to work with Cloudflare, but it’s too much work.