Skip to content

Instantly share code, notes, and snippets.

@jarretmoses
Last active November 12, 2024 12:12
Show Gist options
  • Save jarretmoses/c2e4786fd342b3444f3bc6beff32098d to your computer and use it in GitHub Desktop.
Save jarretmoses/c2e4786fd342b3444f3bc6beff32098d to your computer and use it in GitHub Desktop.
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
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
RN >= 0.63 - watchman watch-del-all && rm -rf node_modules && npm install && rm -rf /tmp/metro-* && npm run start --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
@FilDevTronic
Copy link

@jarretmoses hope someone gives @pmadruga some love for giving us something that really should be a part of the RN out-of-the-box tooling <3

@jigo961257
Copy link

Hey guys i hop all are good ,

I want to clear a console.log clear using programmatically method so how i can do this?
Is there any one know how this happening or doing?

Please help me to solve this. Thank you.

Note : also i upload the pic, so it's clear that what log's i talk about it. 👍

log

@akinolu52
Copy link

@jigo961257

console.clear()

@evangrim
Copy link

evangrim commented Jan 30, 2023

My $TMPDIR ended in /, and current versions of NPM prevent npm cache clean with an error message, so I changed the TMPDIR strings and added --force to npm cache-clean, becoming:

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 --force

The error from NPM suggesting an alternative to npm cache clean --force:

npm ERR! As of npm@5, the npm cache self-heals from corruption issues
npm ERR!   by treating integrity mismatches as cache misses.  As a result,
npm ERR!   data extracted from the cache is guaranteed to be valid.  If you
npm ERR!   want to make sure everything is consistent, use `npm cache verify`
npm ERR!   instead.  Deleting the cache can only make npm go slower, and is
npm ERR!   not likely to correct any problems you may be encountering!
npm ERR! 
npm ERR!   On the other hand, if you're debugging an issue with the installer,
npm ERR!   or race conditions that depend on the timing of writing to an empty
npm ERR!   cache, you can use `npm install --cache /tmp/empty-cache` to use a
npm ERR!   temporary cache instead of nuking the actual one.
npm ERR! 
npm ERR!   If you're sure you want to delete the entire cache, rerun this command
npm ERR!   with --force.

npm ERR! A complete log of this run can be found in:

@techyhoney
Copy link

Here is the response formatted in Markdown:

To clean the npm cache on your system, you should run the npm cache clean command. This will purge any cached packages and modules from the local npm cache folder.

Clearing out the cache can help resolve certain npm errors or inconsistencies, and also frees up disk space by removing redundant packages that have accumulated over time.

For a step-by-step guide on how to use the npm cache clean command, I recommend checking out this handy tutorial: npm clear cache.

It covers the full syntax and provides useful examples of cleaning the npm cache. The tutorial also explains some best practices around when you may want to clear the local cache.

Let me know if running npm cache clean helps resolve the issue you are running into. That TeachingBee article should give you a good overview of how to leverage the command.

@projectninjatech
Copy link

Thank me later or not at all. Either way it's all good:
npm start -- --reset-cache

Worked like a charm! Thanks man.

Works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment