Debugging React Native
Debugging React Native
Debugging
Accessing the In-App Developer Menu
You can access the developer menu by shaking your device or by selecting "Shake
Gesture" inside the Hardware menu in the iOS Simulator. You can also use the ⌘D
keyboard shortcut when your app is running in the iOS Simulator, or ⌘M when running
in an Android emulator on macOS and Ctrl+M on Windows and Linux. Alternatively for
Android, you can run the command adb shell input keyevent 82 to open the dev
menu (82 being the Menu key code).
https://reactnative.dev/docs/debugging 1/12
4/19/23, 7:44 AM Debugging · React Native
in the React Native developer menu. When enabled, most of your edits should be
visible within a second or two.
LogBox
Errors and warnings in development builds are displayed in LogBox inside your app.
Console errors and warnings are displayed as on-screen notifications with a red or
yellow badge, and the number of errors or warning in the console respectively. To view
a console error or warnings, tap the notification to view the full screen information
about the log and to paginate through all of the logs in the console.
Ignore logs as a last resort and create a task to fix any logs that are ignored.
https://reactnative.dev/docs/debugging 2/12
4/19/23, 7:44 AM Debugging · React Native
Unhandled Errors
Syntax Errors
When syntax error occurs the full screen LogBox error will automatically open with the
stack trace and location of the syntax error. This error is not dismissable because it
represents invalid JavaScript execution that must be fixed before continuing with your
app. To dismiss these errors, fix the syntax error and either save to automatically
dismiss (with Fast Refresh enabled) or cmd+r to reload (with Fast Refresh disabled).
Select Tools → Developer Tools from the Chrome Menu to open the Developer Tools.
You may also access the DevTools using keyboard shortcuts ( ⌘⌥I on macOS, Ctrl
Shift I on Windows). You may also want to enable Pause On Caught Exceptions for a
better debugging experience.
Note: on Android, if the times between the debugger and device have drifted; things
such as animation, event behavior, etc., might not work properly or the results may
not be accurate. Please correct this by running adb shell "date `date
+%m%d%H%M%Y.%S%3N`" on your debugger machine. Root access is required for the use
in real device.
Note: the React Developer Tools Chrome extension does not work with React Native,
but you can use its standalone version instead. Read this section to learn how.
https://reactnative.dev/docs/debugging 3/12
4/19/23, 7:44 AM Debugging · React Native
To use a custom JavaScript debugger in place of Chrome Developer Tools, set the
REACT_DEBUGGER environment variable to a command that will start your custom
debugger. You can then select "Debug JS Remotely" from the Developer Menu to start
debugging.
The debugger will receive a list of all project roots, separated by a space. For example, if
you set REACT_DEBUGGER="node /path/to/launchDebugger.js --port 2345 --type
ReactNative" , then the command node /path/to/launchDebugger.js --port 2345 --
type ReactNative /path/to/reactNative/app will be used to start your debugger.
Select your app's JSContext: Develop → Simulator (or other device) → JSContext
Safari's Web Inspector should open which has a Console and a Debugger
While sourcemaps may not be enabled by default, you can follow this guide or video to
enable them and set break points at the right places in the source code.
However, every time the app is reloaded (using live reload, or by manually reloading), a
new JSContext is created. Choosing "Automatically Show Web Inspectors for
JSContexts" saves you from having to select the latest JSContext manually.
npm Yarn
Now run react-devtools from the terminal to launch the standalone DevTools app:
react-devtools
INFO
https://reactnative.dev/docs/debugging 5/12
4/19/23, 7:44 AM Debugging · React Native
If connecting to the emulator proves troublesome (especially Android 12), try running
adb reverse tcp:8097 tcp:8097 in a new terminal.
INFO
If you prefer to avoid global installations, you can add react-devtools as a project
dependency. Add the react-devtools package to your project using npm install --
save-dev react-devtools , then add "react-devtools": "react-devtools" to the
scripts section in your package.json , and then run npm run react-devtools from your
project folder to open the DevTools.
Open the in-app developer menu and choose "Toggle Inspector". It will bring up an
overlay that lets you tap on any UI element and see information about it:
https://reactnative.dev/docs/debugging 6/12
4/19/23, 7:44 AM Debugging · React Native
However, when react-devtools is running, Inspector will enter a collapsed mode, and
instead use the DevTools as primary UI. In this mode, clicking on something in the
simulator will bring up the relevant components in the DevTools:
https://reactnative.dev/docs/debugging 7/12
4/19/23, 7:44 AM Debugging · React Native
You can choose "Toggle Inspector" in the same menu to exit this mode.
When debugging JavaScript in Chrome, you can inspect the props and state of the
React components in the browser console.
First, follow the instructions for debugging in Chrome to open the Chrome console.
Make sure that the dropdown in the top left corner of the Chrome console says
debuggerWorker.js . This step is essential.
Then select a React component in React DevTools. There is a search box at the top
that helps you find one by name. As soon as you select it, it will be available as $r in the
Chrome console, letting you inspect its props, state, and instance properties.
https://reactnative.dev/docs/debugging 8/12
4/19/23, 7:44 AM Debugging · React Native
Performance Monitor
You can enable a performance overlay to help you debug performance problems by
selecting "Perf Monitor" in the Developer Menu.
You can view installation instructions in the README. If you're using Expo, here is an
article detailing how to install on Expo.
https://reactnative.dev/docs/debugging 9/12
4/19/23, 7:44 AM Debugging · React Native
Native Debugging
You may also access these through Debug → Open System Log... in the iOS Simulator
or by running adb logcat "*:S" ReactNative:V ReactNativeJS:V in a terminal while an
Android app is running on a device or emulator.
If you're using Create React Native App or Expo CLI, console logs already appear in
the same terminal output as the bundler.
If you're using Create React Native App or Expo CLI, this is configured for you
already.
On iOS devices, open the file RCTWebSocketExecutor.mm and change "localhost" to the
IP address of your computer, then select "Debug JS Remotely" from the Developer
Menu.
https://reactnative.dev/docs/debugging 10/12
4/19/23, 7:44 AM Debugging · React Native
On Android 5.0+ devices connected via USB, you can use the adb command line tool
to setup port forwarding from the device to your computer:
Alternatively, select "Dev Settings" from the Developer Menu, then update the "Debug
server host for device" setting to match the IP address of your computer.
If you run into any issues, it may be possible that one of your Chrome extensions is
interacting in unexpected ways with the debugger. Try disabling all of your extensions
and re-enabling them one-by-one until you find the problematic extension.
Another option is to run your application using the React Native CLI and attach the
native debugger of the native IDE (Android Studio or Xcode) to the process.
Android Studio
On Android Studio you can do this by going on the "Run" option on the menu bar,
clicking on "Attach to Process..." and selecting the running React Native app.
Xcode
On Xcode click on "Debug" on the top menu bar, select the "Attach to process" option,
and select the application in the list of "Likely Targets".
https://reactnative.dev/docs/debugging 11/12
4/19/23, 7:44 AM Debugging · React Native
https://reactnative.dev/docs/debugging 12/12