wix-incubator / mjml-react

React component library to generate the HTML emails on the fly
MIT License
989 stars 50 forks source link

Unable to run on Cloudflare Workers #83

Closed bduff9 closed 2 years ago

bduff9 commented 2 years ago

Hello! I have a react app running on Cloudflare I am trying to add email capability to. I can send emails without issue, but when I add this library to generate MJML emails, my app will not start up. It fails on start with the following error:

Wrangler-3  | [pages:err] TypeError: globalThis.XMLHttpRequest is not a constructor
Wrangler-3  |     at checkTypeSupport (/Users/bduffey2/projects/test-remix/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js:20:11)
Wrangler-3  |     at node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js (/Users/bduffey2/projects/test-remix/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js:39:45)
Wrangler-3  |     at __init (/Users/bduffey2/projects/test-remix/public/_worker.js:15:56)
Wrangler-3  |     at node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/request.js (/Users/bduffey2/projects/test-remix/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/request.js:1:1)
Wrangler-3  |     at __init (/Users/bduffey2/projects/test-remix/public/_worker.js:15:56)
Wrangler-3  |     at node-modules-polyfills:http (/Users/bduffey2/projects/test-remix/public/node-modules-polyfills:http:30:1)
Wrangler-3  |     at __init (/Users/bduffey2/projects/test-remix/public/_worker.js:15:56)
Wrangler-3  |     at node-modules-polyfills-commonjs:http (/Users/bduffey2/projects/test-remix/public/node-modules-polyfills-commonjs:http:2:18)
Wrangler-3  |     at __require2 (/Users/bduffey2/projects/test-remix/public/_worker.js:18:50)
Wrangler-3  |     at node_modules/clean-css/lib/reader/load-remote-resource.js (/Users/bduffey2/projects/test-remix/node_modules/clean-css/lib/reader/load-remote-resource.js:1:12)
Wrangler-3  | ✘ [ERROR] Could not start Miniflare.

Looks like something is referencing XMLHttpRequest which is not supported on the v8 engine. Any ideas on how to make this work or get around this?

daliusd commented 2 years ago

Hey, no idea where from XMLHttpRequestcomes. Neither mjml-react nor mjml is using this directly. I see node_modules/clean-css/lib/reader/load-remote-resource.js what looks like a problem.

mjml is using this indirectly https://github.com/mjmlio/mjml/blob/a7fa86eaa20be6c4832bf4d810e8381eed4b780a/yarn.lock#L4752

You can try turning off minifier - maybe that will help. As well you might try to use different one if you are using any.

I'm closing this as this is not mjml-react issue.