@@ -42,6 +42,14 @@ export const startDevServer = async (
42
42
staticBaseDirRelativePath : string ,
43
43
port : number ,
44
44
) : 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
+
45
53
devServer = http . createServer ( ( req , res ) => {
46
54
if ( ! req . url ) {
47
55
res . end ( 404 ) ;
@@ -103,10 +111,10 @@ export const startDevServer = async (
103
111
} ) ;
104
112
105
113
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
+ } ) ;
110
118
process . exit ( 1 ) ;
111
119
} ) ;
112
120
@@ -131,6 +139,7 @@ export const startDevServer = async (
131
139
process . cwd ( ) ,
132
140
) ,
133
141
} ;
142
+
134
143
const app = next ( {
135
144
// passing in env here does not get the environment variables there
136
145
dev : isDev ,
@@ -147,7 +156,15 @@ export const startDevServer = async (
147
156
148
157
let isNextReady = false ;
149
158
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
+ }
151
168
isNextReady = true ;
152
169
153
170
const nextHandleRequest :
@@ -176,7 +193,7 @@ const makeExitHandler =
176
193
) =>
177
194
( _codeOrSignal : number | NodeJS . Signals ) => {
178
195
if ( typeof devServer !== 'undefined' ) {
179
- console . log ( '\nshutting down dev server' ) ;
196
+ console . log ( '\n shutting down dev server' ) ;
180
197
devServer . close ( ) ;
181
198
devServer = undefined ;
182
199
}
0 commit comments