183

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?

asked Oct 22, 2017 at 20:06

28 Answers 28

203

For React Native Init approach (without expo) use:

npm start -- --reset-cache
Mohammad Usman
39.6k20 gold badges99 silver badges101 bronze badges
answered Sep 18, 2018 at 9:52
Sign up to request clarification or add additional context in comments.

10 Comments

This helped me to fix Error: unknown
can this be done without starting the metro bundler?
For better approach, before this command close metro bundler and run this.
What does the -- do?
@kojow7 '--' separate options from arguments. Everything after -- npm won't read as option and will pass along to start script (most unix/linux commands follow this option/argument separation convention)
|
136

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
answered Jun 21, 2020 at 19:52

2 Comments

I get "error: unknown option `--reset-cache'" what should I do...?
@Leonard try with yarn cache clean
50

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
answered Jul 17, 2018 at 7:20

4 Comments

This seems the only way possible once got stuck with errors generated from cache that has old code. Really a pain if debugging and used some "console.log" in the RN code. Anyone has some more shorter solution, I mean to avoid that the RN framework use cached code?
Some considerations. 1) not always $TMPDIR variable is defined. 2) watchman command isn't always used. You can remove that part of the command or use ';' instead of '&&' after it 3) the dir names might differ. Mine is /tmp/metro-cache/ , not metro-bundler-cache-something...(RN 0.62)
The best solution I would say
Both npm start and npx react-native start were hanging with no feedback in console whatsoever and this did the trick on RN 0.73.0.
46

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

Expo : expo start -c

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

iOS : Xcode -> Product -> Clean Build Folder

Android : Android Studio -> Build -> Clean Project

answered Jan 12, 2021 at 2:25

1 Comment

This helped on an Expo (based on React Native) project that was having problems.
29

try this

react-native start --reset-cache
answered Jul 8, 2019 at 11:20

Comments

22

For those who are using expo-cli

expo start -c

answered Jan 4, 2019 at 9:28

Comments

14

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
answered Apr 22, 2021 at 10:31

Comments

13

This is what works for me:

watchman watch-del-all && rm -f podfile.lock && rm -rf node_modules && yarn && yarn start --reset-cache
answered Jun 18, 2019 at 8:33

2 Comments

No need to remove your yarn.lock file you'll cause all your dependencies to be updated in the process.
Same with the podfile.lock, shouldn't be removed
9

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.

answered May 22, 2020 at 1:50

Comments

8

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-*
answered May 20, 2020 at 2:47

2 Comments

If I try rm -rf /tmp/metro-* I get zsh: no matches found: /tmp/metro-* I am using RN 0.64.1. Any idea?
Escaping the star seems to work rm -rf /tmp/metro-\*
6

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

answered Feb 26, 2020 at 13:39

Comments

5

For React Native > v0.7 (without expo) use:

watchman watch-del-all
rm -rf yarn.lock package-lock.json node_modules
rm -rf android/app/build
rm ios/Pods ios/Podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData
$TMPDIR/react-native-packager-cache-* $ rm -rf $TMPDIR/metro-bundler-cache-*
npm cache clean --force
yarn cache clean
npm install && cd ios && pod update && cd ..
cd android && ./gradlew clean && cd ..
npm start --reset-cache
answered Oct 23, 2023 at 11:12

Comments

3

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.

answered Jan 4, 2019 at 8:18

Comments

2

React native

 npm start -r-cache

or

yarn cache clean

Expo

expo start -c
answered Nov 1, 2022 at 12:47

Comments

2

npm start -- --reset-cache

Clean build cache

cd android && ./gradlew cleanBuildCache

https://medium.com/@abhisheknalwaya/how-to-clear-react-native-cache-c435c258834e

answered Feb 3, 2023 at 8:04

1 Comment

Please edit to make the relevant technical difference, or appreciated contibution in explanation, more obvious which this provides beyond the existing answers; because the core steps seem very similar to me. Note that linked content is not considered part of the answer post here.
2
  • android cd android && ./gradlew clean
  • ios open xcode then choose product => clear all issue and clean build folder

then yarn start --reset-cache

answered Sep 21, 2023 at 6:08

Comments

1
answered Oct 23, 2017 at 3:16

Comments

1

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

answered Aug 31, 2021 at 19:46

Comments

1

Run in your terminal: expo prebuild --clean

answered Mar 14, 2022 at 8:30

Comments

1

To yarn use

watchman watch-del-all
yarn --reset-cache
answered Feb 5, 2024 at 16:17

Comments

0

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.

answered Jul 26, 2019 at 21:16

Comments

0

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.

answered Sep 18, 2020 at 11:35

Comments

0

For android and Npm

watchman watch-del-all && rm -rf node_modules/ &&
rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* && 
npm cache clean && yarn install && 
npm start --reset-cache
answered Aug 28, 2022 at 21:54

Comments

0

Consider using the below code for a clean ios build:

cd ios && xcodebuild clean && cd .. && npm run ios
rcanpahali
2,6432 gold badges25 silver badges40 bronze badges
answered Apr 4, 2023 at 10:41

Comments

0

Here's some cache cleaning scripts to add to your package.json. It includes a 'secret-cache' workaround to clear a cache that is missed by react-native clean.

They will clean all the build & react-native caches, but not the package or pod caches, which is usually what you want.

 "clean:gradle": "cd android && ./gradlew --stop; rm -rf ~/.gradle/caches/*",
 "clean:android": "yarn clean:secret-cache && react-native clean --include android,metro,watchman",
 "clean:ios": "yarn clean:secret-cache && react-native clean --include metro,watchman && cd ios && xattr -w com.apple.xcode.CreatedByBuildSystem true build && xcodebuild clean; cd ..",
 "clean:secret-cache": "npx react-native start --reset-cache --projectRoot null 1>/dev/null 2>&1 || true",

The 'secret-cache' script will allow your .env updates to work even if you experience the react native dotenv cache bug: https://github.com/goatandsheep/react-native-dotenv#cacheing

Add them to package.json then yarn clean:ios && yarn ios or yarn clean:android && yarn android

In some cases this may still not be enough (e.g. react-native-auth0 still caches auth0Domain). So here's the nuclear option (requires package.json updates above):

# Nuclear option (100% definitely clean everything) - go get a coffee or something
yarn clean:secret-cache && npx react-native clean-project-auto && yarn clean:gradle && yarn && cd android && ./gradlew assemble
answered Sep 21, 2023 at 6:03

Comments

0

I know it's too late to reply but it might help someone:

In case you just want to clear cache just hit this command

npm cache clean --force

Happy coding :)


answered Jul 25, 2024 at 6:38

Comments

0

I solved my react-native cache problem by this way:

  1. open terminal, then cd 'your project root path'
  2. execute this command: npm start -- --reset-cache
  3. open your react native project, If the first run doesn't work, you may need to run it again.
answered Mar 3, 2025 at 5:33

Comments

-3

TO Clear cache in IOS/Xcode

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

rm ~/Library/Developer/Xcode/DerivedData/* 
answered Nov 22, 2021 at 13:06

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.