Skip to content

Commit 1a17219

Browse files
authored
fix(react-email): Import compiled templates with createRequire's require (#2207)
1 parent 6e33167 commit 1a17219

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/hip-items-create.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
fix improper `require` in `email export`

packages/react-email/src/cli/commands/export.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import fs, { unlinkSync, writeFileSync } from 'node:fs';
2+
import { createRequire } from 'node:module';
23
import path from 'node:path';
4+
import url from 'node:url';
35
import type { Options } from '@react-email/components';
46
import { type BuildFailure, build } from 'esbuild';
57
import { glob } from 'glob';
@@ -32,6 +34,10 @@ type ExportTemplatesOptions = Options & {
3234
pretty?: boolean;
3335
};
3436

37+
const filename = url.fileURLToPath(import.meta.url);
38+
39+
const require = createRequire(filename);
40+
3541
/*
3642
This first builds all the templates using esbuild and then puts the output in the `.js`
3743
files. Then these `.js` files are imported dynamically and rendered to `.html` files

0 commit comments

Comments
 (0)