fix(react-email): export Tailwind templates to an outDir outside the project
Related issue or discussion
Closes #3912
What this changes
email export bundles each template into --outDir as a .cjs file and then requires it from there. css-tree is kept external, so the bundle has require("css-tree/dist/csstree.esm") (the specifier the react-email ESM build uses since #3643). Node resolves that from the --outDir location, so a <Tailwind> template fails with Cannot find module 'css-tree/dist/csstree.esm' when --outDir is outside the project, for example --outDir ../backend/templates.
This replaces external: ['css-tree'] with a small esbuild plugin that keeps css-tree external but points the import at the absolute path of the css-tree that the template resolves. The rendered output does not change, and the .cjs files are still deleted after rendering.
Tests:
- New test in
export.spec.tsexports a<Tailwind>template that imports fromreact-email(as an installed project does) into a temporary directory outside the project. It stubsNODE_PATH, because pnpm puts its store there and that hides the failure. It fails oncanarywith the error from the issue and passes with this change. tree.spec.tssnapshot updated for the new file inutils/esbuild.- The new fixture folder is excluded in
tsconfig.json, like the other fixtures that importreact-email. vitest run srcpasses inpackages/react-email, exceptexport-esbuild-plugins.spec.ts > reports a plugins module that fails to load, which spawnspnpmand fails the same way oncanaryon my machine.tsc --noEmitandbiome checkpass.
Checklist
- I understand the code in this PR and the problem it solves.
- I read this description, and it accurately describes the change.
- I added a changeset, or this change doesn't affect a published package.
Summary by cubic
Fixes email export failing with "Cannot find module 'css-tree/dist/csstree.esm'" for <Tailwind> templates when --outDir is outside the project.
The bundles keep css-tree external, but the bare specifier only resolved when the output lived inside the project. A small esbuild plugin now resolves css-tree against the template's own directory and stamps the absolute path into the bundle, so exports work from any --outDir. Rendered output is unchanged, and the temporary .cjs files are still cleaned up.