How to Clear React-Native Cache?

React Native apps use a variety of caches, including packager cache, emulator cache, Gradle cache, and npm cache. These are sometimes helpful, but in other cases, we prefer to remove them so that we can test programs at different places. This article will answer the question: “How to clear react-native cache?” straightforwardly. 

What is the best solution to “clear react-native cache”?

Method 1: If your npm >= 6.0

Active the command one at a time if you have npm >= 6.0 and RN >= 0.50, and that will also clear react-native cache as you wanted. 

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

Method 2: If your npm < 6.0

If you are using npm< 6.0 and RN<0.50, run these commands each individually.

watchman watch-del-all && rm -rf $TMPDIR/react-*

rm -rf node_modules/ && npm cache clean && npm install

npm start -- --reset-cache

That will remove all of the caches successfully without any error.

Method 3: Use the command 

react-native start –reset-cache

This command will launch our React Native app while also clearing all caches.

For npm users, we can use another command. It has the same effect as the command above.

npm start -- --reset-cache

And there are also command for expo users, which are:

expo start -c

Lastly, with yarn users, people can use the following command to clear react-native cache:

yarn cache clean

Now the caches will be clear ideally.

Conclusion

We hope you can find the best way to resolve this whenever you ask yourself, “How to clear react-native cache?” on our page.  If there are any other problems with this error, please comment below, and we will reply as soon as possible! Thank you for reading!

Reference source

https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d

https://stackoverflow.com/questions/46878638/ how-to-clear-react-native-cache

Leave a Reply

Your email address will not be published. Required fields are marked *