| name | mobile-debugging |
| description | Debug React Native apps including metro bundler issues, native errors, performance problems, and crash analysis. Use when troubleshooting errors or investigating issues. |
| allowed-tools | Bash, Read, Grep |
Mobile Debugging
Debugging guide for React Native and Expo applications.
When to Use
- App crashes or freezes
- Metro bundler errors
- Native module issues
- Performance problems
- Build failures
- Network request debugging
Common Issues & Fixes
Metro Bundler Problems
npx expo start --clear
watchman watch-del-all
rm -rf node_modules && npm install
rm -rf /tmp/metro-*
rm -rf /tmp/haste-*
Native Module Errors
cd ios && pod deintegrate && pod install && cd ..
cd android && ./gradlew clean && cd ..
npx expo prebuild --clean
Simulator/Emulator Issues
xcrun simctl erase all
adb devices
adb -s DEVICE_ID emu kill
Debugging Tools
React DevTools
npm install -g react-devtools
react-devtools
Metro Logs
npx expo start --verbose
npx react-native log-ios
npx react-native log-android
adb logcat
Network Debugging
import { Platform } from 'react-native';
if (__DEV__ && Platform.OS === 'ios') {
require('react-native').NativeModules.DevSettings.setIsDebuggingRemotely(true);
}
Performance Debugging
Identify Slow Renders
import { useEffect, useRef } from 'react';
function useRenderTime(componentName: string) {
const start = useRef(performance.now());
useEffect(() => {
const duration = performance.now() - start.current;
if (duration > 16) {
console.warn(`Slow render: ${componentName} took ${duration.toFixed(2)}ms`);
}
});
}
function MyComponent() {
useRenderTime('MyComponent');
return <View>...</View>;
}
Memory Leaks
useEffect(() => {
const subscription = someObservable.subscribe();
const timer = setInterval(() => {}, 1000);
return () => {
subscription.unsubscribe();
clearInterval(timer);
};
}, []);
Error Investigation
JavaScript Errors
Native Errors
Build Errors
npx expo-doctor
node --version
npm --version
npm ls PACKAGE_NAME
Debugging Commands
lsof -ti:8081
lsof -ti:19000
kill -9 $(lsof -ti:8081)
xcrun simctl list devices
adb devices
adb kill-server
adb start-server
Debugging Checklist
When investigating issues:
- Reproduce: Can you consistently trigger the issue?
- Recent Changes: What was changed before it broke?
- Error Message: Read the full error, including stack trace
- Dependencies: Check if packages are compatible
- Platform: Does it happen on iOS, Android, or both?
- Environment: Dev only or production builds too?
- Logs: Check Metro, Xcode, and Logcat for details
Common Error Patterns
- "Unable to resolve module": Check import path and file exists
- "Invariant Violation": React error, check component lifecycle
- "Network request failed": Check API URL and network connection
- "Undefined is not an object": Check for null/undefined before accessing properties
- "Maximum call stack size exceeded": Infinite loop or recursion
Resources