ReactNative启动报错Error: listen EADDRINUSE: address already in use :::8081

1,033 阅读1分钟

问题

ReactNative项目运行总是报算口被占用

error listen EADDRINUSE: address already in use :::8081.
Error: listen EADDRINUSE: address already in use :::8081
    at Server.setupListenHandle [as _listen2] (net.js:1316:16)
    at listenInCluster (net.js:1364:12)
    at Server.listen (net.js:1450:7)
    at /Users/yuki01.ye/Documents/Workspace/gitlab/demo/flatListDemo/node_modules/metro/src/index.js:208:16
    at new Promise (<anonymous>)
    at Object.exports.runServer (/Users/yuki01.ye/Documents/Workspace/gitlab/demo/flatListDemo/node_modules/metro/src/index.js:207:10)
    at async Object.runServer [as func] (/Users/yuki01.ye/Documents/Workspace/gitlab/demo/flatListDemo/node_modules/@react-native-community/cli-plugin-metro/build/commands/start/runServer.js:123:26)
    at async Command.handleAction (/Users/yuki01.ye/Documents/Workspace/gitlab/demo/flatListDemo/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

解决方法一:杀掉占用进程 (不管用)

查找占用的进程pid

sudo lsof -i :8080

杀掉对应进程

sudo kill [pid]

然而再运行总是报被占用,重新启动电脑也还是有占用

COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME

macmnsvc 111 root   20u  IPv6 0x1c2a7bd5bc0af595      0t0  TCP *:sunproxyadmin (LISTEN)

解决方案二: 换端口

yarn start --port=8088