Skip to content

Commit 57b8bb8

Browse files
authored
fix(preview-server): custom JSX runtime not running properly in ESM projects (#2381)
1 parent 02505a3 commit 57b8bb8

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/wet-ideas-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/preview-server": patch
3+
---
4+
5+
fix custom JSX runtime trying to be run as ESM on ESM projects

packages/preview-server/jsx-runtime/jsx-dev-runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This hack is necessary because React forces the use of the non-dev JSX runtime
22
// when NODE_ENV is set to 'production', which would break the data-source references
33
// we need for stack traces in the preview server.
4-
const ReactJSXDevRuntime = require('react/jsx-dev-runtime');
4+
import ReactJSXDevRuntime from 'react/jsx-dev-runtime';
55

66
export function jsxDEV(type, props, key, isStaticChildren, source, self) {
77
const newProps = { ...props };

packages/preview-server/src/utils/create-jsx-runtime.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ export const createJsxRuntime = async (
1818
'node_modules',
1919
'.react-email-jsx-runtime',
2020
);
21+
if (!fs.existsSync(jsxRuntimePath)) {
22+
await fs.promises.mkdir(jsxRuntimePath, {
23+
recursive: true,
24+
});
25+
await fs.promises.writeFile(
26+
path.join(jsxRuntimePath, 'package.json'),
27+
'{"type": "commonjs"}',
28+
'utf8',
29+
);
30+
}
2131
await esbuild.build({
2232
bundle: true,
2333
outfile: path.join(jsxRuntimePath, 'jsx-dev-runtime.js'),

0 commit comments

Comments
 (0)