How to clear react-native cache?
Without further ado, here's how to quickly and efficiently zap your React Native cache:
-
Reset metro cache:
-
Clear watchman artifact:
-
Refresh dependencies:
-
Clean iOS build folder:
-
Clean Android Gradle project:
If you're using Expo:
Shake up your Expo environment with this command.
Deep dive into cache clearing
Mastering npm cache
When the usual tools fail to do the trick, npm
's cache could be the hidden suspect. A force clean is then the way to go:
While this option eliminates all npm goodies, it should not be your first resort due to its broad brushstroke effect.
Maintaining npm and React Native versions
Keeping your npm
and React Native
versions in sync helps to stave off version conflicts. The package.json
file can be your compass, assisting in navigating the compatibility maze.
A deeper cleanse
Looking for a thorough cleanse? Consider clearing temporary directories associated with your React Native project:
This helps to eradicate stubborn storage locations lingering with outdated information.
Handling your cache like a pro
Tailored treatments for iOS and Android
For an environmentally sound approach in clearing cache, considering the specific Operating Systems is beneficial:
For iOS
Additional to performing xcodebuild clean
, clearing Derived Data can bring you closer to the solution:
For Android
With caches residing in various nooks and corners, apart from executing ./gradlew clean
:
- Clear the build cache:
- Remove the Gradle wrapper cache directory:
Cache control in network operations
Network caching issues, such as image caching, can be handled by:
- Resetting Network Settings on your device or simulator.
- Using libraries (such as axios) to set
cache-control
headers on your network requests.
Was this article helpful?