Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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
@HunterMeyer

This comment has been minimized.

Copy link

HunterMeyer commented Apr 8, 2017

Thanks for this. Though I think you want npm cache clean.

@jarretmoses

This comment has been minimized.

Copy link
Owner Author

jarretmoses commented Apr 14, 2017

Good catch thanks!

@abdurrahmanekr

This comment has been minimized.

Copy link

abdurrahmanekr commented May 11, 2017

Thanks

@leabdalla

This comment has been minimized.

Copy link

leabdalla commented Jul 9, 2017

maybe you could also remove the build folder? is this a good idea?

@e2goon

This comment has been minimized.

Copy link

e2goon commented Jul 18, 2017

wow!! gode code!!

@jarretmoses

This comment has been minimized.

Copy link
Owner Author

jarretmoses commented Jul 26, 2017

Hey @leabdalla do you mean the ios and android builds?

@alxvallejo

This comment has been minimized.

Copy link

alxvallejo commented Sep 3, 2017

npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.

@sjones6

This comment has been minimized.

Copy link

sjones6 commented Sep 18, 2017

@alxvallejo : You can add --force to force a cache clear (including in the message from NPM after the quoted bit): npm cache clean --force

@mrsof

This comment has been minimized.

Copy link

mrsof commented Sep 25, 2017

My 50cents. Windows and Android version (from react-native root project)
del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache

or

del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & yarn install & react-native run-android

@jarretmoses

This comment has been minimized.

Copy link
Owner Author

jarretmoses commented Oct 5, 2017

@sjones6 @mrsof thanks for the input will try them out and update!

@kamalkech

This comment has been minimized.

Copy link

kamalkech commented Nov 4, 2017

not working i get some error :

React Native version mismatch.

JavaScript version: 0.50.0
Native version: 0.49.3

Make sure that you have rebuilt the native code. If the problem persists try clearing the Watchman and packager caches with watchman watch-del-all && react-native start --reset-cache.
checkVersions
index.bundle?platform=android&dev=true&minify=false:9761:20

index.bundle?platform=android&dev=true&minify=false:9618:38
loadModuleImplementation
index.bundle?platform=android&dev=true&minify=false:127:12
guardedLoadModule
index.bundle?platform=android&dev=true&minify=false:79:45
_require
index.bundle?platform=android&dev=true&minify=false:64:77
global code
index.bundle?platform=android&dev=true&minify=false:51662:9

@DevStar423

This comment has been minimized.

Copy link

DevStar423 commented Nov 6, 2017

@kamalkech Any updates?

I've used react-native@0.50.1 and got same issue.

@slorber

This comment has been minimized.

Copy link

slorber commented Dec 6, 2017

for RN50 the tmp cache files seems to have a different name

"clear": "rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-*",
@leoskyrocker

This comment has been minimized.

Copy link

leoskyrocker commented Dec 27, 2017

Thanks @slorber, you saved my life, clearing the metro caches was necessary.

@khanhtdbse

This comment has been minimized.

Copy link

khanhtdbse commented Jan 11, 2018

@kamalkech
Thank for --reset-cache :)

@jarretmoses

This comment has been minimized.

Copy link
Owner Author

jarretmoses commented Jan 11, 2018

@kamalkech sorry for the delay. I haven't updated this to match recent versions of React Native. I will be doing a revamp of this and testing against more recent versions. Ideally in the future I will be better at keeping this up to date. @slorber thanks for that response, I will update this gist accordingly and give some options per versioning

@mjstelly

This comment has been minimized.

Copy link

mjstelly commented Jan 12, 2018

Watchman readme says the package is deprecated. Does the gist need to be updated?

@baoanhng

This comment has been minimized.

Copy link

baoanhng commented Jan 19, 2018

Save my fecking time. Everytime I installed new package it's been 'undefined undefined'

@zamberform

This comment has been minimized.

Copy link

zamberform commented Feb 27, 2018

As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid

it will be::::::::
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache

@raktec

This comment has been minimized.

Copy link

raktec commented Mar 12, 2018

very simple to clear cache below code
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res


@nlothian

This comment has been minimized.

Copy link

nlothian commented Mar 14, 2018

Note that for me (Ubuntu 16.10) $TMPDIR wasn't set.

@sterswift

This comment has been minimized.

Copy link

sterswift commented Mar 28, 2018

Thank you very much, worked for me!

@kleosus

This comment has been minimized.

Copy link

kleosus commented Apr 20, 2018

Thank you very much, worked for me too

@ztl8702

This comment has been minimized.

Copy link

ztl8702 commented May 15, 2018

How does it work on Windows?

@kyungjoongo

This comment has been minimized.

Copy link

kyungjoongo commented Jun 7, 2018

How does it work on Windows?

@nzrsrk

This comment has been minimized.

Copy link

nzrsrk commented Jul 17, 2018

watchman is not an internal and external command how to fix it??

@JOsktgui

This comment has been minimized.

Copy link

JOsktgui commented Jul 19, 2018

I thought about just deleting the cache, not node_modules

@joshua-turner

This comment has been minimized.

Copy link

joshua-turner commented Jul 24, 2018

At least with RN 0.56 I also had to run rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-*

@syyam

This comment has been minimized.

Copy link

syyam commented Jul 28, 2018

just npm cache clean && npm install && npm start -- --reset-cache worked for me

@Dimon70007

This comment has been minimized.

Copy link

Dimon70007 commented Aug 7, 2018

no need to call npm install. in RN 0.55 for cleaning js cache just enough:

watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/metro* && rm -rf $TMPDIR/haste-*
@marcio-eric

This comment has been minimized.

Copy link

marcio-eric commented Aug 15, 2018

Thank you!

@harisanwar64

This comment has been minimized.

Copy link

harisanwar64 commented Sep 18, 2018

For React Native (without Expo) use: react-native run-android -- --reset-cache

@nilocoelhojunior

This comment has been minimized.

Copy link

nilocoelhojunior commented Sep 28, 2018

Thank you!

@sanderkaz

This comment has been minimized.

Copy link

sanderkaz commented Oct 5, 2018

Thank you! deleting node_modules & npm install & npm start -- --reset-cache works fine.

@bsaqqa

This comment has been minimized.

Copy link

bsaqqa commented Oct 16, 2018

Thanks ♥

@yangkezun

This comment has been minimized.

Copy link

yangkezun commented Nov 1, 2018

@harisanwar64 it works for me

@yangkezun

This comment has been minimized.

Copy link

yangkezun commented Nov 1, 2018

@harisanwar64 Thanks

@laurentlemaire

This comment has been minimized.

Copy link

laurentlemaire commented Nov 13, 2018

I have tried it all and I'm still facing the "unable to resolve module .... does not exist in the haste module map".
I'm running it on IOS simulator on a Mac, with RN 0.55.2
I've tried:

  • Clearing npm cache
  • Running watchman watch-del-all
  • Removing haste file from temp
  • Removing metro files from temp
  • Removing react files from temp
  • Removing node_modules & install

Any idea?

@onusvishal

This comment has been minimized.

Copy link

onusvishal commented Dec 12, 2018

-bash: clear: rm: command not found

@StephenTANM

This comment has been minimized.

Copy link

StephenTANM commented Dec 13, 2018

My 50cents. Windows and Android version (from react-native root project)
del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache

or

del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & yarn install & react-native run-android

Thanks!

@kasperpihl

This comment has been minimized.

Copy link

kasperpihl commented Dec 14, 2018

I had so many issues on clearing the cache. Turns out that the metro bundler and haste map has changed their directory structure. 👎

This is the script I use to clean the cache:
watchman watch-del-all && rm package-lock.json && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && npm install

This has costed us DAYS, hope this helps someone :)

@torchhound

This comment has been minimized.

Copy link

torchhound commented Dec 16, 2018

Sometimes removing ~/.rncache/ can also help.

@ashishcompwiz

This comment has been minimized.

Copy link

ashishcompwiz commented Dec 18, 2018

go to C:\Users<Username>\AppData\Local\Temp and delete metro-cache .
It will solve your problem

@jskod

This comment has been minimized.

Copy link

jskod commented Dec 28, 2018

npm cache clean will not clean the cache unless --force flag is passed.

@jetobe95

This comment has been minimized.

Copy link

jetobe95 commented Jan 17, 2019

thnkssss

@mikebridge

This comment has been minimized.

Copy link

mikebridge commented Feb 7, 2019

For me the haste-map* file is in $TEMP on Windows:

Remove-Item $env:TEMP\haste-map*
@nubwang

This comment has been minimized.

Copy link

nubwang commented Feb 19, 2019

Delete everything on the computer

@denisinla

This comment has been minimized.

Copy link

denisinla commented Feb 27, 2019

I had so many issues on clearing the cache. Turns out that the metro bundler and haste map has changed their directory structure.

This is the script I use to clean the cache:
watchman watch-del-all && rm package-lock.json && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && npm install

This has costed us DAYS, hope this helps someone :)

Thanks for the find! I adjusted your command a bit since I was using yarn.

watchman watch-del-all && rm yarn.lock && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && yarn
@kerembalcan

This comment has been minimized.

Copy link

kerembalcan commented Apr 12, 2019

I had so many issues on clearing the cache. Turns out that the metro bundler and haste map has changed their directory structure.
This is the script I use to clean the cache:
watchman watch-del-all && rm package-lock.json && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && npm install
This has costed us DAYS, hope this helps someone :)

@kasperpihl I am facing the same issue now. I didn't read your comment before I run "npm cache clean --force" then suddenly metro bundler's started looking files in my Desktop, not in the project root. I managed to fix path issue by setting project root in metro.config.js but it complains about haste map too. I wonder how did you solve it?

@Jullib

This comment has been minimized.

Copy link

Jullib commented Apr 12, 2019

My 50cents. Windows and Android version (from react-native root project)
del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
or
del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & yarn install & react-native run-android

Why it do not work in my project? (((
I enter these commands in the project folder, it says to me that ""watchman" - not internal or external
command executing a program or batch file".
What am I doing wrong?

@Gregory-Canonne

This comment has been minimized.

Copy link

Gregory-Canonne commented Apr 22, 2019

the solution is simple :
=> nameToYourProject/ios/build (remove)
=> remove node-modules
=> npm install
=> react-native run-ios
End !

@krozett

This comment has been minimized.

Copy link

krozett commented Jun 7, 2019

Even simpler solution:
npm uninstall -g react-native-cli
rm -rf ~/Projects/react-native-*
echo "127.0.0.1 facebook.github.io" > /etc/hosts

Leave RN in the trash where it belongs. You'll thank me.

@firofame

This comment has been minimized.

Copy link

firofame commented Jun 18, 2019

This is what works for me:
watchman watch-del-all && rm -f yarn.lock && rm -rf node_modules && yarn && yarn start --reset-cache

@tereshchenkoartyom94

This comment has been minimized.

Copy link

tereshchenkoartyom94 commented Jun 19, 2019

Even simpler solution:
npm uninstall -g react-native-cli
rm -rf ~/Projects/react-native-*
echo "127.0.0.1 facebook.github.io" > /etc/hosts

Leave RN in the trash where it belongs. You'll thank me.

This is the best solution!

@arled

This comment has been minimized.

Copy link

arled commented Jun 21, 2019

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

@samtheson

This comment has been minimized.

Copy link

samtheson commented Jul 9, 2019

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

@arled Thank you 💥

@yagoazedias

This comment has been minimized.

Copy link

yagoazedias commented Jul 10, 2019

@mrsof tips to clean cache worked to me

@jbburf

This comment has been minimized.

Copy link

jbburf commented Aug 2, 2019

Me as well, thanks @HunterMeyer!

@jarretmoses

This comment has been minimized.

Copy link
Owner Author

jarretmoses commented Aug 2, 2019

Sorry everyone obviously this has become out of date. I will look through the comments and make an updated version. Thanks for sharing!

@waqaramjad

This comment has been minimized.

Copy link

waqaramjad commented Oct 24, 2019

for RN50 the tmp cache files seems to have a different name

"clear": "rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-*",

is that command is for windows ?

@Sanjulapro

This comment has been minimized.

Copy link

Sanjulapro commented Nov 3, 2019

can you guys tell me where to type this command in my terminal(path)??

@jotapepinheiro

This comment has been minimized.

Copy link

jotapepinheiro commented Nov 5, 2019

#!/bin/sh
BLUE='\033[0;34m'
NC='\033[0m'

echo "${BLUE}==>1. Refresh watchman${NC}"
watchman watch-del-all

echo "${BLUE}==>2. Remove cache and node_module${NC}"
rm -rf $TMPDIR/react-* &&
rm -rf $TMPDIR/metro-bundler-cache-* &&
rm -rf node_modules/ &&
yarn cache clean

echo "${BLUE}==>3. Re-install libraries${NC}"
yarn install &&
react-native link &&
yarn start -- --reset-cache

echo "${BLUE} Reset successful!${NC}"
@gilshaan

This comment has been minimized.

Copy link

gilshaan commented Nov 11, 2019

Clean cache

rm -rf $TMPDIR/react-; rm -rf $TMPDIR/haste-; rm -rf $TMPDIR/metro-*; watchman watch-del-all

@kroska

This comment has been minimized.

Copy link

kroska commented Nov 18, 2019

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

@arled Thank you 💥

tks!!

@JungDonggun

This comment has been minimized.

Copy link

JungDonggun commented Nov 25, 2019

Thank you 😙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.