node:events:496
throw er; // Unhandled ‘error’ event
^
Error: listen EADDRINUSE: address already in use 0.0.0.0:5000
at Server.setupListenHandle [as _listen2] (node:net:1908:16)
at listenInCluster (node:net:1965:12)
at doListen (node:net:2139:7)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted ‘error’ event on WebSocketServer instance at:
at Server.emit (node:events:518:28)
at emitErrorNT (node:net:1944:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: ‘EADDRINUSE’,
errno: -98,
syscall: ‘listen’,
address: ‘0.0.0.0’,
port: 5000
}
Node.js v20.18.1
Open the shell and run npx kill-port 5000, refresh the page, hit start again and it should work.
1 Like
Thanks I spent at least $1 fixing it with agent the four times it game up today
Kody it didn’t work, here’s what I tried…
Process:
- After detecting the (listen EADDRINUSE:) error I ran the port command
- Refresh page
- Clicked the main ‘Run’ (green with the play button) button
- As you can see from the screenshot Repl is still stalled out. I’ll keep trying…
I changed the port from 5000 to 5001, didn’t work, tried port 3000 didn’t work, tried port 3001 didn’t work. Spent another 25 cents with agent to turn the repl back on because assistant couldn’t do it and none of the commands worked.
That error means the port is in use by both the agent doing a workflow and by the WebView trying to run the app. You have to kill the process on the port with that command, hit Stop, refresh, just confirm that nothing’s running on that port anymore before trying to hit run again. You can also in the terminal run kill 1 to hard reset the repl.
Recommend you dont try to get agent/assistant to debug that issue, they’re bad at editing their own configuration files like that. There’s fixes in the works to make them more reliable, and on agent v2 it’s much harder to end up in that conflicting ports state.
Ok, got it! Thank ChatGPT o1Pro Deep Research
Step 1. pkill -f node || true
Step 2. Modify file “server/index.ts”
// Try to use environment variable PORT if available, otherwise fallback to 4000
let port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
// Function to try listening on a port and increment if busy
const startServer = (retryPort: number, maxRetries = 10) => {
const tryListen = (currentPort: number, retriesLeft: number) => {
server.listen({
port: currentPort,
host: “0.0.0.0”,
reusePort: true,
})
.on(“listening”, () => {
log(serving on port ${currentPort});
// Update PORT environment variable to the actual port used
process.env.PORT = currentPort.toString();
})
.on(“error”, (err: NodeJS.ErrnoException) => {
if (err.code === ‘EADDRINUSE’ && retriesLeft > 0) {
log(Port ${currentPort} is busy, trying ${currentPort + 1}...);
tryListen(currentPort + 1, retriesLeft - 1);
} else {
log(Failed to start server: ${err.message});
throw err;
}
});
};
tryListen(retryPort, maxRetries);
};
startServer(port);
})();
Step 3: npm run dev
I ran into this issue much less with Agent v1 / Claude Sonnet 3.5, it happened maybe once a week with the old configuration but now I’m seeing it more often. I’m hoping my new fix is the silver buIIet for this error! Agent v2 is happy and capable to fix it 100% of the time, for a fee.
1 Like