React Native Watchman失效求助:无法重载应用同步代码变更
Hey there, I totally get how frustrating it is when your React Native app's reload stops working—especially when shaking the device does nothing, and even restarting the packager doesn't help. Let's walk through some tried-and-true fixes to get your live/hot reload back up and running:
1. Reset Watchman's State First
Watchman often gets stuck with stale watchers. Let's completely reset it to clear any glitches:
# Shut down the Watchman server watchman shutdown-server # Delete all existing watchers watchman watch-del-all # Verify Watchman is ready (it'll auto-start when needed) watchman version
2. Clear React Native Packager Cache
Stale cache is one of the most common culprits for unresponsive reloads. Reset it with:
# For npm users npm start -- --reset-cache # For yarn users yarn start --reset-cache
Once the packager restarts, try shaking your device again to trigger reload—this fixes most cases right away.
3. Verify Android Device Connection & Permissions
Sometimes the issue isn't Watchman at all, but a flaky device connection:
- Run
adb devicesin your terminal to confirm your device is listed and marked as "device" (not "unauthorized"). - If it's unauthorized, disconnect and reconnect your device, then approve the USB debugging prompt on your phone.
- Make sure USB debugging (security settings) is enabled in your device's Developer Options—this lets the packager send reload commands to your device.
- You can also manually bring up the dev menu without shaking: run
adb shell input keyevent 82, then tap "Reload" from the menu.
4. Ensure Watchman is Watching Your Project
Double-check that Watchman is actively monitoring your project directory:
# List all current Watchman watchers watchman watch-list
If your project isn't listed, add it manually:
watchman watch-project /path/to/your/react-native-project
5. Fix Watchman Permissions (MacOS Specific)
On MacOS, Watchman might lack access to your project folder:
- Open System Settings > Privacy & Security > Full Disk Access
- Add Watchman to the list of approved apps (you can find it at
/usr/local/bin/watchmanif installed via Homebrew)
6. Check Version Compatibility
Outdated or mismatched versions of Watchman and React Native can cause conflicts:
- Update Watchman:
brew upgrade watchman(if using Homebrew) - If updating breaks things, try downgrading to a stable version (e.g., Watchman 4.9.0):
brew uninstall watchman brew install watchman@4.9.0 brew link --force watchman@4.9.0 - Ensure your React Native version is up to date (check official docs for compatible Watchman versions)
7. Clear Android Build Cache
If all else fails, wipe your Android project's build cache to eliminate stale build artifacts:
cd android ./gradlew clean cd ..
Then restart the packager and rebuild your app.
内容的提问来源于stack exchange,提问作者alfredopacino

