How to Clear React Native Cache (Step-by-Step)
In this article
Clearing the React Native cache is a standard troubleshooting step that removes stale build artifacts, resolved module metadata, and temporary files that can cause unexplained errors, slow bundling, or outdated UI after code changes. This guide walks you through the fastest and most reliable ways to reset every cache layer—Metro, npm/yarn, and native build caches—without losing your source code or configuration.
What You'll Need
- A terminal (Command Prompt, PowerShell, or any Unix shell) open in your project's root directory.
- Node.js and npm or yarn installed (check with
node -vandnpm -voryarn -v). - For iOS: Xcode command line tools (usually already set up). For Android: Android Studio and SDK.
- Optional but recommended: a clean git working tree (commit or stash changes) so you can revert if needed.
Step-by-Step
- Stop all running Metro and app processes. Close the terminal windows running
react-native startornpx react-native run-*. Also stop the app on your simulator/device. On macOS, you can pressCtrl+Cin the terminal; on Windows useCtrl+Cor close the window. - Clear the Metro bundler cache. Run this command from your project root:
npx react-native start --reset-cache
This clears the Metro cache and starts a fresh bundler. Wait until you see the “Metro waiting on” message, then pressCtrl+Cto stop it (or keep it running if you’ll test immediately). - Clear npm or yarn cache.
- If using npm:
npm cache clean --force - If using yarn:
yarn cache clean
node_modulesstays intact. - If using npm:
- Delete the
node_modulesfolder and reinstall dependencies.rm -rf node_modules
Then install fresh:npm install
oryarn install
This ensures no corrupted or outdated packages remain. - Clear native build caches.
- Android: Run
cd android && ./gradlew clean(orgradlew.bat cleanon Windows). This deletes thebuild/folders and intermediate files. - iOS: Delete the derived data folder:
rm -rf ~/Library/Developer/Xcode/DerivedData(or open Xcode → Preferences → Locations → Derived Data → click the arrow and delete the folder). Also runcd ios && pod installto reinstall CocoaPods dependencies if you use them.
- Android: Run
- Clear the React Native specific cache (optional). Some versions store temporary files in
~/.rncache(macOS/Linux) or%LOCALAPPDATA%\rncache(Windows). Delete that folder if it exists. - Restart everything. Start the Metro bundler again:
npx react-native start. Then run your app:npx react-native run-androidornpx react-native run-ios. For iOS, you may need to build from Xcode first.
Common Mistakes
- Forgetting to stop Metro before clearing. If Metro is still running, it may recreate the cache immediately, making your steps pointless.
- Only clearing one cache. The error might be in the native build cache, not the JS cache. Always clear both.
- Deleting
node_moduleswithout reinstalling. Running the app with no dependencies will cause module-not-found errors. - Using
--reset-cachewith an old CLI version. In older React Native versions, the flag was--reset-cache; in newer ones it’s still supported, but if you get an error, usenpx react-native start --reset-cacheor just delete the/tmp/metro-*folders manually. - Not clearing the watchman cache. Watchman (used by Metro) can also hold stale file states. Run
watchman watch-del-alland thenwatchman shutdown-serverbefore restarting.
Tips
- Create a script. Add a
clean.shorclean.batfile in your project root with the commands above so you can run them in one go. - Use
npx react-native-clean-project. This community package automates all cache clearing steps. Install it globally or run via npx:npx react-native-clean-project. It will prompt you for what to clear—choose “all”. - Keep the Metro cache for daily work. Only clear it when you suspect stale data. Frequent clearing slows initial builds.
- After clearing, run a fresh build. The first build may take longer than usual—that’s normal.
- If you use Expo, run
expo start -cto clear the Metro cache and start fresh.
Troubleshooting
- Still seeing the same error after clearing? Check if the error is actually a code issue. Read the full stack trace—if it points to a file in your
srcfolder, it’s likely a logic bug, not cache. - Metro fails to start with “EACCES” or permission errors. This often happens on macOS/Linux due to folder permissions. Run
sudo chown -R $(whoami) node_modulesandsudo chown -R $(whoami) /tmp/metro-*(if they exist) then retry. - Android build fails with “SDK location not found”. Ensure your
local.propertiesfile points to the correct SDK path, or setANDROID_HOMEenvironment variable. - iOS build fails after clearing derived data. Reinstall pods:
cd ios && pod install. If you don’t use CocoaPods, check that your Xcode project references the correct paths. - App runs but shows old code. Make sure you’re not running a release build that wasn’t rebuilt. Do a clean build (as described) and reinstall the app on the simulator/device.
- If nothing works, try creating a new React Native project and copying your
srcandpackage.jsonover. This isolates whether the issue is in your project configuration.
Frequently Asked Questions
Will clearing the cache delete my source code?
No. The cache only contains temporary build artifacts, resolved module metadata, and downloaded packages. Your source files in src, App.js, etc., are untouched.
How often should I clear the React Native cache?
Only when you encounter issues like stale UI, module resolution errors, or weird build failures. Regular clearing is unnecessary and slows down development.
Does clearing the cache affect my installed npm packages?
It removes the npm/yarn cache, but that’s just a download cache. Your node_modules folder remains until you delete it (as in step 4). Reinstalling will re-download packages.
What is the difference between --reset-cache and deleting node_modules?
--reset-cache clears Metro’s transform cache (JS bundles). Deleting node_modules removes installed dependencies. They address different layers; you often need both.
Can I clear only the native cache (Android/iOS) without touching JS?
Yes. Run cd android && ./gradlew clean for Android, or delete DerivedData for iOS. This is useful when the JS bundle works but the native build fails.
Why does my first build after clearing take so long?
Because everything—dependencies, native modules, and JS bundles—must be rebuilt from scratch. Subsequent builds will be faster as caches repopulate.