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

React Native打包器启动异常求助:npm start后打包器无限启动

Fixing React Native Metro Bundler Infinite Startup Issue

Hey there, sorry to hear you're stuck with the Metro bundler hanging indefinitely when running npm start—let’s walk through some common fixes that usually resolve this, especially for folks new to React Native following the official docs!

Here are the steps to try, in order of how likely they are to solve your problem:

  • Reset Metro's cache
    Cached files are the #1 culprit for this kind of hang. Run this command instead of plain npm start:

    npm start -- --reset-cache
    

    If that doesn’t work, you can manually delete the Metro cache directory:

    • On Mac/Linux: rm -rf ~/.metro-cache
    • On Windows: Delete the folder at %USERPROFILE%/.metro-cache
  • Verify your Node.js version
    React Native requires specific Node versions (usually the latest LTS release). Check your current version with:

    node -v
    

    If it’s not matching the version specified in React Native’s official setup docs, consider using a version manager like nvm (for Mac/Linux) or nvm-windows to switch to a compatible version.

  • Reinstall dependencies
    Sometimes partial or corrupted installs cause issues. Delete your node_modules folder and lock file, then reinstall:

    rm -rf node_modules package-lock.json  # On Windows, use rmdir /s node_modules and del package-lock.json
    npm install
    
  • Check for port conflicts
    Metro uses port 8081 by default. If another app is using this port, the bundler can’t start properly.

    • Mac/Linux: Check what’s using port 8081 with lsof -i :8081, then kill the process with kill -9 <PID> (replace <PID> with the number from the output).
    • Windows: Run netstat -ano | findstr :8081 to find the PID, then open Task Manager to end that process.
      Alternatively, start Metro on a different port:
    npm start -- --port 8082
    
  • Disable firewall/proxy temporarily
    Local firewalls or proxy settings can block Metro from connecting. Try turning them off briefly to see if the bundler starts—if it does, you’ll need to add an exception for Metro or adjust your proxy settings.

  • Double-check environment setup
    Make sure you’ve completed all steps from the official setup docs:

    • For Android: Verify ANDROID_HOME and JAVA_HOME environment variables are set correctly, and you’ve installed all required SDK components.
    • For iOS: Ensure Xcode is up to date and you’ve installed the command-line tools (xcode-select --install).

Try these steps one by one, and I bet one of them will get your bundler running smoothly!

内容的提问来源于stack exchange,提问作者E.Belekov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:24:46