@@ -37,20 +37,23 @@ import { createStatusCommand } from './status/index.js'
37
37
import { createSwitchCommand } from './switch/index.js'
38
38
import { createUnlinkCommand } from './unlink/index.js'
39
39
import { createWatchCommand } from './watch/index.js'
40
-
40
+ import { AddressInUseError } from './types.js'
41
41
const SUGGESTION_TIMEOUT = 1e4
42
42
43
- process . on ( 'uncaughtException' , async ( err : any ) => {
44
- console . log ( '' )
45
43
46
- if ( err . code === 'EADDRINUSE' ) {
44
+ process . on ( 'uncaughtException' , async ( err : AddressInUseError | Error ) => {
45
+
46
+ if ( 'code' in err && err . code === 'EADDRINUSE' ) {
47
47
error (
48
48
`${ chalk . red ( `Port ${ err . port } is already in use` ) } \n\n` +
49
- `This could be due to one of your serverless functions initializing a server\n` +
50
- `to listen on port ${ err . port } without properly closing it.\n\n` +
49
+ `Your serverless functions might be initializing a server\n` +
50
+ `to listen on specific port without properly closing it.\n\n` +
51
+ `This behavior is generally not advised\n` +
51
52
`To resolve this issue, try the following:\n` +
52
- `1. Check if any other applications are using port ${ err . port } \n` +
53
- `2. Review your serverless functions for any lingering server connections\n` ,
53
+ `1. If you NEED your serverless function to listen on a specific port,\n` +
54
+ `use a randomly assigned port as we do not officially support this.\n` +
55
+ `2. Review your serverless functions for lingering server connections, close them\n` +
56
+ `3. Check if any other applications are using port ${ err . port } \n` ,
54
57
{ exit : false } ,
55
58
)
56
59
} else {
0 commit comments