Skip to content

Commit aa518a3

Browse files
authored
fix(react-email): No explicit error when running with Node <= 17 (#1923)
1 parent e634544 commit aa518a3

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.changeset/breezy-planes-attend.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+
Add an explicit error when running Node <= 17

packages/react-email/src/cli/utils/preview/start-dev-server.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export const startDevServer = async (
4242
staticBaseDirRelativePath: string,
4343
port: number,
4444
): Promise<http.Server> => {
45+
const [majorNodeVersion] = process.versions.node.split('.');
46+
if (majorNodeVersion && Number.parseInt(majorNodeVersion) < 18) {
47+
console.error(
48+
` ${logSymbols.error} Node ${majorNodeVersion} is not supported. Please upgrade to Node 18 or higher.`,
49+
);
50+
process.exit(1);
51+
}
52+
4553
devServer = http.createServer((req, res) => {
4654
if (!req.url) {
4755
res.end(404);
@@ -103,10 +111,10 @@ export const startDevServer = async (
103111
});
104112

105113
devServer.on('error', (e: NodeJS.ErrnoException) => {
106-
console.error(
107-
` ${logSymbols.error} preview server error: `,
108-
JSON.stringify(e),
109-
);
114+
spinner.stopAndPersist({
115+
symbol: logSymbols.error,
116+
text: `Preview Server had an error: ${e}`,
117+
});
110118
process.exit(1);
111119
});
112120

@@ -131,6 +139,7 @@ export const startDevServer = async (
131139
process.cwd(),
132140
),
133141
};
142+
134143
const app = next({
135144
// passing in env here does not get the environment variables there
136145
dev: isDev,
@@ -147,7 +156,15 @@ export const startDevServer = async (
147156

148157
let isNextReady = false;
149158
const nextReadyPromise = app.prepare();
150-
await nextReadyPromise;
159+
try {
160+
await nextReadyPromise;
161+
} catch (exception) {
162+
spinner.stopAndPersist({
163+
symbol: logSymbols.error,
164+
text: ` Preview Server had an error: ${exception}`,
165+
});
166+
process.exit(1);
167+
}
151168
isNextReady = true;
152169

153170
const nextHandleRequest:
@@ -176,7 +193,7 @@ const makeExitHandler =
176193
) =>
177194
(_codeOrSignal: number | NodeJS.Signals) => {
178195
if (typeof devServer !== 'undefined') {
179-
console.log('\nshutting down dev server');
196+
console.log('\n shutting down dev server');
180197
devServer.close();
181198
devServer = undefined;
182199
}

0 commit comments

Comments
 (0)