'React native Error: The HTTP/S server is already being used by another WebSocket server

I'm trying to run yarn start, not working for me. I have tried changing port but it gives the same result.

┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8084.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

warning: the transform cache was reset.
master/node_modules/ws/lib/websocket-server.js:83
        throw new Error(
        ^

Error: The HTTP/S server is already being used by another WebSocket server
    at new WebSocketServer (/node_modules/ws/lib/websocket-server.js:83:15)
    at InspectorProxy._addDeviceConnectionHandler (/node_modules/metro-inspector-proxy/src/InspectorProxy.js:220:17)
    at InspectorProxy.addWebSocketListener (/node_modules/metro-inspector-proxy/src/InspectorProxy.js:175:10)
    at Server.<anonymous> (/node_modules/metro/src/index.js:265:28)
    at Object.onceWrapper (node:events:509:28)
    at Server.emit (node:events:390:28)
    at emitListeningNT (node:net:1368:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Please help! Thanks in advance!



Solution 1:[1]

This may happen for a few reasons:

  1. You have run the app using react-native run-android or directly from Android Studio (or XCode). When running this command, if the Metro bundler server is not active, it will start it. Doing so, it open the default Terminal.app on Mac and appear in your recent app if not pinned. So if you run manually afterward yarn start the port will already be used.

  2. You are trying to start a second Metro bundler on the same port.

Recommanded solution

Find the already running server on this port using

sudo lsof -i :8084

Kill it

kill -9 <PID>

Alternative

Change the Metro port.

react-native start --port 8088

You'll need to access the developer menu on each app re-install to change the bundler location: localhost:8088 for example.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hugo Gresse