Skip to main content

Debugging Expo Applications

1. Using React DevTools

Feature Description Usage
React DevTools Browser-based devtools for inspecting React component trees Install via npm: npm install -g react-devtools
Expo DevTools Integrated debugging tools in Expo Go app Open dev menu in Expo Go and select "DevTools"

Example: Inspecting Components

import React from 'react';
import { View, Text } from 'react-native';

const MyComponent = () => {
  return (
    <View>
      <Text>Hello, world!</Text>
    </View>
  );
};

export default MyComponent;
Note: React DevTools can be used to inspect component props, state, and performance metrics.
Warning: Ensure that React DevTools is not used in production builds as it may expose sensitive data.

2. Using Chrome DevTools

Example: Enable Chrome DevTools for Expo

// In your Expo project, run:
npx expo start --tunnel

// Then in the Expo DevTools menu:
// - Select "Debug" or "Open DevTools"
// - This opens Chrome DevTools with your app
Feature Description Availability
Console Logs View console.log() output in Chrome DevTools Supported
Breakpoints Set breakpoints in JavaScript code via source tab Supported
Network Inspection Inspect network requests made by the app Supported
Storage Inspection View localStorage, AsyncStorage data in Application tab Supported
Note: Chrome DevTools for Expo apps work best when connected via LAN or tunnel mode.
Warning: Changes made in DevTools do not persist to the actual app code.

Key Features of Chrome DevTools in Expo

  • Real-time console logging
  • JavaScript debugging with breakpoints
  • Network request monitoring
  • Storage inspection (AsyncStorage, localStorage)

3. Using Flipper

Flipper is a debugging tool for mobile applications, including Expo apps. It provides a graphical interface to inspect network requests, logs, and application state.

Feature Description Availability
Network Inspection Inspect HTTP/HTTPS requests and responses made by the app. NEW in Flipper v0.202
Logs View console logs and errors from the app in real-time. Stable
State Inspector Inspect the application's state and component tree. Stable

Example: Setting up Flipper with Expo

// Install Flipper in your project
npm install flipper

// Or with Yarn
yarn add flipper
Note: Flipper requires the Flipper desktop app to be installed and running before debugging.
Warning: Flipper does not support debugging on physical devices in production builds.

4. Inspecting Network Requests

Example: Using Expo DevTools to Inspect Network Requests

// Enable network inspection in Expo DevTools
// Open Expo DevTools in browser and navigate to "Network" tab

// Example API call being monitored
fetch("https://api.example.com/data", {
  method: "GET",
  headers: {
    "Authorization": "Bearer <token>"
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Fetch error:", error));
Request Property Description Notes
URL https://api.example.com/data Endpoint being called
Method GET HTTP method used
Headers Authorization: Bearer <token> Authentication header
Status Code 200 OK Response status
Response Time 120ms Time taken to receive response
Note: Network inspection is only available when running the app in development mode with Expo DevTools enabled.
Warning: Sensitive data in headers or responses should not be exposed during debugging.

Network Inspection Tips

  • Use the Network tab in Expo DevTools to monitor all outgoing requests.
  • Filter by XHR or Fetch to isolate API calls.
  • Inspect request and response bodies for debugging data flow issues.

5. Viewing Console Logs

Log Level Description Usage
console.log Basic logging output Used for general debugging information
console.info Informational messages For less critical status updates
console.warn Warning messages To indicate potential issues
console.error Error messages To report errors or exceptions

Example: Logging in Expo

console.log("App started");
console.info("User logged in");
console.warn("Deprecated API used");
console.error("Failed to fetch data");
Note: In Expo Go, logs appear in the terminal where you started the development server.

Steps to View Logs in Expo Go

  1. Start your Expo project with expo start
  2. Open the Expo Go app on your device or emulator
  3. Scan the QR code to connect to the development server
  4. Open the developer menu (shake device or press Ctrl + D)
  5. Select "Dev Tools" to open the React Native Debugger
  6. View logs in the console tab

Console Log Levels Comparison

  • console.log: Basic output, no special styling
  • console.info: Informational, often styled differently in DevTools
  • console.warn: Warning messages, usually highlighted in yellow
  • console.error: Error messages, typically shown in red and include stack traces

6. Setting Breakpoints

Feature Description Usage
React Native Debugger Debugging tool for React Native apps with breakpoints support import { Alert } from 'react-native';\nAlert.alert('Breakpoint', 'Paused at breakpoint');
Expo DevTools Browser-based debugging interface with breakpoint capabilities console.log('Breakpoint here');
Chrome DevTools Debugging via Chrome's DevTools console and debugger debugger;

Example: Setting Breakpoint in Code

function handlePress() {
  console.log('Before breakpoint');
  debugger; // Execution will pause here
  console.log('After breakpoint');
}
Note: Breakpoints in Expo apps work similarly to React Native apps. Use debugger; statement or set breakpoints in the browser's DevTools.

7. Using React Native Debugger

Feature Description Usage
Debugger Connection Connects to React Native apps for debugging Start the debugger and connect via network
Console Logs View console logs from the app Logs appear in the debugger console
Network Inspection Inspect network requests made by the app View request/response details in the Network tab
State Inspection Inspect component and Redux state Use the Components and Store tabs to inspect state

Example: Connecting to React Native Debugger

npm install -g react-native-debugger

Example: Starting Debugger

react-native-debugger-open
Note: Ensure the debugger is running before starting your Expo app.
Warning: Make sure the debugger is not running on a different port than expected.

8. Debugging Native Code

Example: Enabling Native Debugging in Expo

// Enable native debugging in Expo
import { Constants } from 'expo-constants';

// Check if app is running in development mode
if (Constants.appOwnership === 'expo') {
  console.log('Native debugging enabled');
}
Platform Debugging Method Notes
iOS expo run:ios --device Use Xcode for native debugging
Android expo run:android --device Use Android Studio for native debugging
Note: Native debugging requires the Expo Go app or a development build.
Warning: Debugging native code may impact performance in production builds.

Native Debugging Workflow

  • Ensure Expo CLI is installed
  • Run app with expo run:ios or expo run:android
  • Open native IDE (Xcode or Android Studio)
  • Attach debugger to running process

9. Using LogBox

Example: Basic LogBox Usage

import { LogBox } from 'expo';

// Ignore specific warnings
LogBox.ignoreLogs([
  'Warning: componentWillMount is deprecated',
  'Remote debugger'
]);

// Ignore all warnings
LogBox.ignoreAllLogs(true);
Method Description Notes
LogBox.ignoreLogs() Suppresses specific warnings by message regex Accepts array of strings or regex patterns
LogBox.ignoreAllLogs() Suppresses all warnings from LogBox Boolean parameter to enable/disable
Note: LogBox is part of Expo's debugging tools and helps in identifying and suppressing non-critical warnings during development.

10. Inspecting Component Hierarchy

Example: Using React DevTools

// Install React DevTools
npm install --save-dev react-devtools

// In your app entry point
import { LogBox } from 'react-native';
LogBox.ignoreAllLogs(true);

// Enable React DevTools
import { DevSettings } from 'react-native';
DevSettings.addFPSProvider(() => {
  console.log('FPS:', performance.now());
});
Tool Description Usage
React DevTools Inspect component tree and state Connect via Expo DevTools or React Native Debugger
Expo DevTools Integrated debugging tools in Expo Open in browser at exp://your-ip-address
Note: React DevTools requires react-devtools to be installed in your project.
Warning: Component hierarchy inspection may not work in production builds.

11. Profiling Performance

Tool Description Usage
React Native Debugger Debugging tool with performance profiling capabilities npm install -g react-native-debugger
Flipper Mobile debugging tool with performance monitoring Install Flipper desktop app and enable in Expo project
Expo DevTools Built-in performance tools in Expo Go Open DevMenu and select "Profile" to start profiling

Example: Using React Native Debugger

import { AppState } from 'react-native';

AppState.addEventListener('change', (state) => {
  console.log('App state changed to:', state);
});
Note: Performance profiling is most effective in development builds.
Warning: Profiling can impact app performance and should be disabled in production.
Feature Status Notes
CPU Profiling NEW Available in Expo SDK 50+
Memory Profiling DEPRECATED Removed in SDK 49, use React Native Debugger instead
Network Profiling BETA Experimental in SDK 50

12. Using Source Maps

Property Description Default Notes
expo.sourceMap Enables or disables source map generation false Set to true to enable source map generation for debugging
expo.sourceMapFile Path to the generated source map file undefined Used to specify a custom path for the source map file

Example: Enabling Source Maps in Expo Config

{
  "expo": {
    "sourceMap": true,
    "sourceMapFile": ".expo/source-map.json"
  }
}
Note: Source maps are essential for debugging production builds in Expo. They help map minified code back to the original source, making it easier to identify and fix issues.
Warning: Source maps can increase the size of your build and should be disabled in production builds if not needed for debugging.

Was this article helpful?