You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux环境下React Native npm start报错(端口8081被占用)及相关问题

Fixing "EADDRINUSE :::8081" Error in React Native Android on Linux

Hey there, let's cut straight to the core of your issue: that Error: listen EADDRINUSE :::8081 line makes it clear the default Metro Bundler port (8081) is already occupied by another process. That's why your npm start fails, and react-native run-android gets stuck loading—your app can't connect to the bundler it needs to load code.

You've already tried some general React Native troubleshooting steps (cleaning node_modules, reinstalling watchman), but let's target the port conflict directly with these solutions:

1. Identify and Kill the Process Using Port 8081

First, find out which program is hogging the port:

  • Run this command to list processes using port 8081:
    lsof -i :8081
    
    Look for the PID column (the numerical ID of the process using the port).
  • If lsof isn't installed on your system, use this alternative command:
    netstat -tulpn | grep 8081
    
  • Once you have the PID, terminate the process with:
    sudo kill -9 <PID>
    
    Replace <PID> with the actual number you found (e.g., sudo kill -9 1234).

2. Start Metro on a Different Port (If You Need to Keep 8081 in Use)

If you can't kill the process using 8081, just tell Metro to use an alternative port:

  • Start the bundler with a custom port:
    npm start -- --port 8082
    
  • Then run your Android app pointing to the new port:
    react-native run-android --port 8082
    
  • To make this permanent, add a metro.config.js file in your project root with:
    module.exports = {
      server: {
        port: 8082,
      },
    };
    

3. Extra Troubleshooting to Cover All Bases

Since you already tried reinstalling node_modules and watchman, add these checks to ensure everything is working:

  • Reset Metro's cache (this often fixes stuck loading issues even after resolving port conflicts):
    npx react-native start --reset-cache
    
  • After reinstalling watchman, close your terminal and open a new one to ensure the changes take effect.
  • Verify watchman is installed correctly with:
    watchman version
    

Quick Note on Your Project Setup

Your package.json looks completely standard for React Native 0.59.5—no configuration issues stand out here. The problem is 100% related to the port conflict, not your project's dependencies or scripts.

Give these steps a try, and your app should load properly once Metro can start up successfully!

内容的提问来源于stack exchange,提问作者mad_greasemonkey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:09:37