Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 38 ยท Testing and Performance

Debugging and Profiling Expo Apps

Find and fix bugs in an Expo app: React Native DevTools, console logs, error boundaries, network inspection, native logs, expo-doctor, Sentry crash reporting and profiling steps.

Every developer spends more time finding bugs than writing features. Good debugging is a method, not luck: reproduce the problem, shrink it, look at real data, change one thing. Expo and React Native give you good tools for each step, from console.log to a full debugger and production crash reports.

What runs on this site. The debugger and device logs need a running app, so those commands are read-only. The runnable stand-ins are small, real JavaScript patterns that you would put in your app: a logger, an error boundary's catching logic and a timing helper.

Start with the dev server

npx expo start prints a menu in the terminal. Press j to open the debugger, r to reload, m to open the dev menu, a/i to launch Android or iOS, shift+m for more tools. Shake the device (or press Ctrl+M on an Android emulator, Cmd+D on iOS simulator) to open the dev menu.

Errors appear as a red LogBox screen (errors) or yellow banner (warnings). Read the first line of the message and the first stack frame that points into your own files; ignore frames from node_modules at first.

Logging that helps

console.log works and prints in your terminal and the debugger. Make it better:

JavaScript
console.log('user', user);               // object
console.table(items);                    // rows as a table
console.time('load'); await load(); console.timeEnd('load');
console.warn('slow response');           // yellow
console.error('failed', error);          // red LogBox

Remove noisy logs before release (console.log costs time on the JS thread), or wrap them in a logger that is silent in production:

Node.js A small leveled logger

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

React Native DevTools

Press j in the terminal to open React Native DevTools (a Chrome DevTools based debugger for Hermes). You get:

  • Console: your logs and a prompt to run code in the app.
  • Sources: set breakpoints, step through code and inspect variables. Add a debugger; statement to pause exactly where you need.
  • Network: requests made with fetch (in recent versions), including status and timing.
  • Components: the React tree with props, state and hooks. Click a component, see why it rendered, edit state live.
  • Profiler: record renders to see which components render and how long they take.

Source maps are on by default, so you see your original code, not the bundle.

Debugging the network

When data is wrong, find out whether the request or the response is at fault:

  1. Check the Network panel in DevTools: URL, method, status, response body.
  2. Log the exact request you send (headers, body) in your API helper from the networking lesson.
  3. Test the same URL with curl. If curl works and the app fails, suspect headers, HTTPS or the base URL.
  4. On a real device, localhost is the phone, not your computer. Use your computer's LAN IP (http://192.168.1.20:3000) or a tunnel (npx expo start --tunnel).
  5. Android blocks plain http in release builds; use HTTPS.

Catching errors

Two kinds of failures need different tools:

  • Render errors (a component throws while rendering) crash the whole tree unless an error boundary catches them.
  • Async or event errors (rejected promises, errors in handlers) are not caught by boundaries. Use try/catch, and a global handler as a last resort.
JSX
import { Component } from 'react';
import { Text, View } from 'react-native';

export class ErrorBoundary extends Component {
  state = { error: null };
  static getDerivedStateFromError(error) { return { error }; }
  componentDidCatch(error, info) { reportError(error, info.componentStack); }
  render() {
    if (this.state.error) {
      return <View><Text>Something went wrong.</Text></View>;
    }
    return this.props.children;
  }
}

With Expo Router you can also export an ErrorBoundary component from any route file; Router wraps that route with it and passes error and retry props.

Node.js Wrap risky work and report it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

In React Native, ErrorUtils.setGlobalHandler((error, isFatal) => ...) plays the role of that last-resort handler for uncaught exceptions.

Crash reporting in production

Users do not send you stack traces. Add a service such as Sentry (@sentry/react-native has an Expo config plugin and an npx @sentry/wizard setup) so crashes and errors arrive with a stack trace, device, OS version and breadcrumbs of what the user did. Upload source maps during your EAS build so minified traces map back to your code. Tag events with the app version and update id so you know which release a bug came from.

Respect privacy: do not attach personal data, scrub tokens from breadcrumbs, and mention the tool in your privacy policy.

Native problems

If the app crashes before JavaScript runs, or a native module misbehaves, JavaScript tools show nothing. Look at native logs:

Terminal
adb logcat *:E ReactNative:V ReactNativeJS:V     # Android
npx expo run:ios --device                        # build locally and see Xcode logs

Typical native causes: a missing config plugin, a permission not declared, mismatched package versions. Three commands solve most of them:

Terminal
npx expo-doctor              # checks your project for known problems
npx expo install --check     # lists packages whose versions do not match your SDK
npx expo start --clear       # clears Metro's cache after odd bundling errors

If you suspect stale native code, rebuild the development client (eas build --profile development) or run npx expo prebuild --clean.

Profiling

When the problem is "slow", not "broken", measure:

  • Perf monitor in the dev menu: JS and UI frame rates. A dropping JS FPS means JavaScript work; a dropping UI FPS means heavy native views or animations.
  • React DevTools Profiler: record, interact, and read which components rendered and why. Fix with the techniques in List and render performance.
  • Hermes sampling profiler in DevTools: shows which functions take the most time.
  • Android Studio Profiler / Xcode Instruments for memory and native CPU.

Always profile a release-like build; development mode is intentionally slower.

Node.js A timing helper for suspicious code

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

A debugging routine

  1. Reproduce reliably; write down the steps.
  2. Read the error and its first relevant stack frame.
  3. Shrink: comment out code or make a tiny repro until the bug disappears, then add things back.
  4. Inspect real values with breakpoints or logs instead of guessing.
  5. Change one thing, test, repeat.
  6. Prevent: add a test (Testing with Jest) so the bug stays fixed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you open React Native DevTools from the dev server?

    Pressing j in the Expo CLI opens the debugger connected to Hermes.
  2. 2. Which errors does an error boundary NOT catch?

    Boundaries only catch render-phase errors. Handlers and async code need try/catch.
  3. 3. Your phone cannot reach http://localhost:3000. Why?

    Use your computer's LAN IP address or a tunnel.
  4. 4. What does npx expo install --check do?

    It compares installed versions with those Expo expects and offers to fix mismatches.

Summary

  • Use the dev menu, LogBox and structured logs, and read the first relevant stack frame.
  • React Native DevTools gives breakpoints, a network view, a component tree and a profiler.
  • Boundaries catch render errors; use try/catch and a global handler for async errors.
  • Add Sentry-style crash reporting with source maps for production.
  • expo-doctor, install --check and --clear fix many environment problems; measure before optimizing.

Next: Project: a habit tracker