How to clear react-native cache?

JavascriptJavaAndroidReactjsReact Native

Javascript Problem Overview


In react-native development, there are multiple caches used when the app is built:

  1. React-native packager cache
  2. Emulator cache
  3. Java side cache (.gradle) folder (only in android)
  4. npm cache (if relevant?)

Am I missing something also? Because I'm trying to clear cache in react-native, to be able to repeat a bug that only occurs on first usage. But clearing those caches above did not help. This is on android. When the app is building, most of the rows DO NOT say UP-TO-DATE, as expected, because I cleared the cache.

But, there are still many rows where this text is printed. Like:

> app:preBuild UP-TO-DATE > > app:preDebugBuild UP-TO-DATE > > :app:preReleaseBuild UP-TO-DATE

The question is, how can I clear the whole cache related to react-native development?

Javascript Solutions


Solution 1 - Javascript

For React Native Init approach (without expo) use:

npm start -- --reset-cache

Solution 2 - Javascript

Simplest one(react native,npm and expo )

For React Native

react-native start --reset-cache

for npm

npm start -- --reset-cache

for Expo

expo start -c

Solution 3 - Javascript

Clearing the Cache of your React Native Project:

npm < 6.0 and RN < 0.50:

 watchman watch-del-all && rm -rf $TMPDIR/react-* &&
 rm -rf node_modules/ && npm cache clean && npm install && 
 npm start -- --reset-cache

npm >= 6.0 and RN >= 0.50:

 watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* &&
 rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean --force &&
 npm install && npm start -- --reset-cache

Solution 4 - Javascript

try this

react-native start --reset-cache

Solution 5 - Javascript

For those who are using expo-cli

> expo start -c

Solution 6 - Javascript

Currently, it is built using npx, so it needs to be updated.

Terminal : npx react-native start --reset-cache

IOS : Xcode -> Product -> Clean Build Folder

Android : Android Studio -> Build -> Clean Project

Solution 7 - Javascript

This is what works for me:

watchman watch-del-all && rm -f podfile.lock && rm -rf node_modules && yarn && yarn start --reset-cache

Solution 8 - Javascript

Below commands worked for me for Android and Yarn,

cd android && ./gradlew cleanBuildCache && cd .. &&
watchman watch-del-all && rm -rf node_modules/ &&
rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* &&  
yarn cache clean && yarn install && 
yarn start --reset-cache

Solution 9 - Javascript

Here's a great discussion on GitHub which helped me a lot. Clearing the Cache of your React Native Project by Jarret Moses

There are solutions for 4 different instances.

  1. RN <0.50 -
    watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

  2. RN >=0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

  3. NPM >=5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache

  4. Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache

The solution is similar to Vikram Biwal's Answer.

And there is a discussion below in the given link, so even if the above 4 cases don't work for you, you can scroll through and find a possible solution.

Solution 10 - Javascript

If you are using WebStorm, press configuration selection drop down button left of the run button and select edit configurations:

edit configurations

Double click on Start React Native Bundler at bottom in Before launch section:

before launch

Enter --reset-cache to Arguments section:

arguments

Solution 11 - Javascript

Clearing the Cache of your React Native Project: if you are sure the module exists, try this steps:

  1. Clear watchman watches: npm watchman watch-del-all
  2. Delete node_modules: rm -rf node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-*

Solution 12 - Javascript

Solution 13 - Javascript

You can clean cache in React Native >= 0.50 and npm > 5 :

watchman watch-del-all && 
rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* && 
rm -rf node_modules/ 
&& npm cache clean --force &&
npm install && 
npm start -- --reset-cache

Apart from cleaning npm cache you might need to reset simulator or clean build etc.

Solution 14 - Javascript

Well.. i want to share my experience about this issue:

I was facing this problem, and when I opened the task manager I notice many tasks being executed, and they were linked to my project folder.

So I restarted my PC, and when it turned on, I could install all I needed, so the problem got solved itself, it worked to me, hope this help somebody...

Solution 15 - Javascript

I had a similar problem, I tried to clear all the caches possible (tried almost all the solutions above) and the only thing that worked for me was to kill the expo app and to restart it.

Solution 16 - Javascript

I went into this issue today, too. The cause was kinda silly -- vscode auto imported something from express-validator and caused the bug.

Just mentioning this in case anyone has done all the steps to clear cache/ delete modules or what not.

Solution 17 - Javascript

Run in your terminal: expo prebuild --clean

Solution 18 - Javascript

TO Clear cache in IOS/Xcode

Delete folders in /Users/{YOUR_USERNAME}/Library/Developer/Xcode/DerivedData/ and try again.

rm ~/Library/Developer/Xcode/DerivedData/* 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVille Miekk-ojaView Question on Stackoverflow
Solution 1 - JavascriptHaris AnwarView Answer on Stackoverflow
Solution 2 - JavascriptßãlãjîView Answer on Stackoverflow
Solution 3 - JavascriptVikram BiwalView Answer on Stackoverflow
Solution 4 - JavascriptspacedevView Answer on Stackoverflow
Solution 5 - JavascriptMohsinView Answer on Stackoverflow
Solution 6 - Javascripthong developerView Answer on Stackoverflow
Solution 7 - JavascriptFiroz AhmedView Answer on Stackoverflow
Solution 8 - JavascriptmmafrarView Answer on Stackoverflow
Solution 9 - JavascriptGlitch_ZnabView Answer on Stackoverflow
Solution 10 - JavascriptOlcay ErtaşView Answer on Stackoverflow
Solution 11 - JavascriptFabricio CunhaView Answer on Stackoverflow
Solution 12 - Javascriptsebastianf182View Answer on Stackoverflow
Solution 13 - JavascriptAbhishek NalwayaView Answer on Stackoverflow
Solution 14 - JavascriptDaniel NascimentoView Answer on Stackoverflow
Solution 15 - JavascriptJack WireView Answer on Stackoverflow
Solution 16 - JavascriptEddie LamView Answer on Stackoverflow
Solution 17 - JavascriptDaniel DanieleckiView Answer on Stackoverflow
Solution 18 - JavascriptillusionistView Answer on Stackoverflow