How to clear the React native Cache
In this tutorial, we are going to learn about how to clear or remove the cache from a React native app.
When we install a packages using the npm install <package-name>
command npm stores the cache inside the user file system.
The default cache directory is ~/.npm
on Posix (mac or linux), or %AppData%/npm-cache
on Windows.
Clearing the cache in React native
To clear a cache in react native app, we need to run the npm start -- --reset-cache
command in our terminal.
Here is an example:
npm start -- --reset-cache
If the above command doesn’t not clear your cache, follow the below steps.
- First, clean the
npm
cache by using the following command.
npm cache clean --force
- Delete the
node_modules
folder andpackage-lock.json
file using:
rm -rf node_modules package-lock.json
or you can delete it manually by right-clicking on it and select the delete
option.
- Now, re-install the npm packages again by running the below command.
npm install
- Start the development server using the appropriate command, like
npm start
ornpm run dev
. It will work successfully without any errors.