Ova

How to connect React Native debugger with React Native app?

Published in React Native Debugging 6 mins read

To connect the React Native Debugger with your React Native app, you need to first ensure your application is running in development mode, then launch the standalone debugger and select your app from the available connections.

Effective debugging is crucial for developing robust React Native applications. The standalone React Native Debugger provides a comprehensive set of tools, including a Redux Inspector, React DevTools, and network request monitoring, all integrated into a single interface. This guide will walk you through the steps to successfully connect and utilize it for your development workflow.


What is React Native Debugger?

The React Native Debugger is a powerful desktop application that bundles various debugging tools into one convenient interface. It's an essential utility for developers, offering a more streamlined experience than relying solely on the in-app developer menu. Key features include:

  • Chrome Developer Tools Integration: Access to console, network, elements, and sources tabs, similar to web development.
  • React DevTools: Inspect and modify React component hierarchies and states.
  • Redux DevTools: Monitor Redux actions, state changes, and time-travel debugging (if using Redux).
  • Offline Support: Can be used even without an active internet connection.

Prerequisites

Before you begin, ensure you have the following set up:

  • Node.js and npm/Yarn: Installed on your development machine.
  • A React Native Project: An existing React Native application that you are actively developing.
  • Emulator, Simulator, or Physical Device: Your app needs to be running on one of these.

Installing React Native Debugger

The React Native Debugger is a standalone application, separate from your project dependencies.

Installation Options:

  1. Homebrew (macOS Recommended):
    For macOS users, Homebrew is the easiest way to install.

    brew install --cask react-native-debugger
  2. Direct Download (Windows, Linux, macOS):
    You can download the latest release for your operating system from the official GitHub repository:

    • Go to React Native Debugger Releases.
    • Download the appropriate .dmg (macOS), .exe (Windows), or .AppImage/.deb (Linux) file and follow the installation instructions.
  3. npm/Yarn (Global Installation - Less Common for UI App):
    While possible, it's generally recommended to use the standalone desktop application for a better user experience.

    npm install -g react-native-debugger-client
    # OR
    yarn global add react-native-debugger-client

    If you install it globally, you would typically run rndebugger from your terminal to launch it.


Connecting React Native Debugger to Your App

The connection process is straightforward and relies on your app running in development mode.

Step-by-Step Connection Guide:

  1. Start Your React Native App in Development Mode:

    • Ensure your React Native application is running on an emulator, simulator, or physical device. For instance, if you're developing locally:
      npx react-native run-android
      # OR
      npx react-native run-ios
    • It's crucial that your app is running in development mode. The debugger typically won't connect to production builds.
  2. Open React Native Debugger:

    • Once your app is actively running, launch the standalone React Native Debugger application you installed. On macOS, you can find it in your Applications folder; on Windows, via the Start Menu.
  3. Establish Connection:

    • The debugger should automatically detect your running app. You will typically see a list of active connections (often just one if only your app is running).
    • Select your application from this list of running connections to establish the link. If it doesn't connect automatically, you might see a blank screen or a "Waiting for React Native to connect..." message.
  4. Access Developer Menu (If Auto-Connect Fails):

    • If the debugger doesn't automatically connect, or if you need to manually trigger debugging:
      • iOS Simulator: Press Cmd + D
      • Android Emulator: Press Cmd + M or Ctrl + M
      • Physical Device: Shake the device.
    • From the in-app Developer Menu, select "Debug remote JS" (or "Debug" on older versions). This explicitly tells your app to connect to a debugger.
    • Note: The React Native Debugger typically listens on port 8081 (for rndebugger://set-debugger-loc?host=localhost&port=8081) or 19000 (for Expo). You can usually leave the default port unless you have conflicts.
  5. Explore the Debugger:

    • Upon successful connection, the debugger will display its interface.
    • Navigate to the Sources tab within the debugger. Here, you will find a familiar interface displaying all your project files and folders, similar to how they appear in browser developer tools (like Chrome DevTools). This allows you to set breakpoints, inspect variables, and step through your JavaScript code.

Common Debugging Scenarios

Here's a table summarizing common debugging actions within the React Native Debugger:

Feature Action Description
Inspect UI Go to the "React" tab (React DevTools). View and modify component hierarchy, props, and state in real-time.
View Console Go to the "Console" tab. See console.log outputs, warnings, and errors from your app.
Network Calls Go to the "Network" tab. Monitor API requests, responses, and performance.
Set Breakpoints Go to the "Sources" tab, navigate to a file, and click on a line number. Pause code execution at specific points to inspect variables and step through logic.
Redux State Go to the "Redux" tab (Redux DevTools). Track Redux actions, state changes, and dispatch custom actions for testing.

Troubleshooting Connection Issues

If you encounter difficulties connecting, consider these common solutions:

  • Ensure App is Running: Double-check that your React Native app is actively running on your device/emulator.
  • "Debug Remote JS" Enabled: Make sure you've selected "Debug Remote JS" from your app's developer menu.
  • Port Conflicts: The debugger typically uses port 8081 (or 19000 for Expo). If another process is using this port, the debugger might fail to connect. You can usually configure the debugger's port in its settings or kill the conflicting process.
    • On macOS/Linux, you can check with lsof -i :8081 and kill with kill -9 <PID>.
  • Reload JavaScript: Sometimes simply reloading the JavaScript bundle (R twice in the emulator, or "Reload" from the dev menu) can re-establish the connection.
  • Clear Cache: Run npx react-native start --reset-cache to clear the Metro bundler cache, then try again.
  • Update Debugger: Ensure you're using the latest version of React Native Debugger, as older versions might have compatibility issues with newer React Native versions.
  • Firewall: Check if a firewall is blocking the connection between your app and the debugger.

By following these steps, you can reliably connect your React Native app to the React Native Debugger, unlocking powerful tools to streamline your development and debugging process.