shellscape / jsx-email

Build emails with a delightful DX
https://jsx.email
MIT License
991 stars 33 forks source link

Edge runtime #82

Open cprussin opened 10 months ago

cprussin commented 10 months ago

Expected Behavior / Situation

Compatibility with Edge runtime (vercel etc)

Actual Behavior / Situation

Not compatible with Edge runtime -- throws Module not found: Can't resolve 'os' due to clean-css:

⨯ ../../node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/options/format.js:1:22
Module not found: Can't resolve 'os'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
../../node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/clean.js
../../node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/index.js
../../node_modules/.pnpm/rehype-minify-css-style@4.0.0/node_modules/rehype-minify-css-style/lib/index.js
../../node_modules/.pnpm/rehype-minify-css-style@4.0.0/node_modules/rehype-minify-css-style/index.js
../../node_modules/.pnpm/rehype-preset-minify@7.0.0/node_modules/rehype-preset-minify/index.js
../../node_modules/.pnpm/@jsx-email+render@3.0.1/node_modules/@jsx-email/render/dist/index.mjs

Modification Proposal

I don't know much about what jsx-email is using clean-css for but perhaps there's an alternate library that could be used instead which is compatible with the Edge runtime and only uses web-compatible APIs?

sisheng1998 commented 2 months ago

Coming from react-email, I'm using cloudflare pages with next-on-pages for my nextjs app, react-email/tailwind package are too large until can't deploy it in cloudflare pages.

So I switch to jsx-email, after amending the code to fit jsx-email, I hit a lot of errors from clean-css: Module not found: Can't resolve 'fs' Module not found: Can't resolve 'path'

Any idea on how to fix this?

shellscape commented 2 months ago

@sisheng1998 this entire issue is about getting the package to work correctly on the edge. I suggest you read the entire thread.

shellscape commented 3 weeks ago

the v2.0.0 PR is up and gets us closer to where we want to be for edge compat https://github.com/shellscape/jsx-email/pull/206

this will let you optionally include the minify plugin. i'm planning a cloudflare integration test following this release (thanks to our friends at SST) which will help guarantee edge compat moving forward.

shellscape commented 2 days ago

v2 release will happen around 1PM ET tomorrow. A Cloudflare recipe and direct support will be my top priority afterwards.