The short answer
To delete all data out of the cache folder on Linux, macOS and Windows, you can use the following npm cache command:
$ npm cache clean --force
Run in Warp
To then verify that the cache has been successfully cleared, you can run the following command:
$ npm cache verify
Run in Warp
Easily retrieve this command using Warp’s AI Command Search
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:
Entering clear npm cache in the AI Command Search will prompt an npm command that can then quickly be inserted into your shell by doing CMD+ENTER.
The npm cache system
When installing a package for the first time, npm will download the package in the node_modules folder of the project and automatically add a local copy of this package into the cache folder.
In the future, when reinstalling the same package, npm will reuse this local copy to speed up the installation process instead of downloading it again from the registry.
On Unix-like operating systems, the cache folder is located in the ~/.npm directory, and on Windows, in the %LocalAppData%\npm-cache directory.
Note that there is, at the moment, no available npm command to easily verify the content of the cache folder.
Why clear the npm cache
As of npm@5, all data that passes through the cache is fully verified and automatically refetched in case of corruption. For this reason, it should never be necessary to clear the cache for any reason other than reclaiming disk space or reinstalling libraries free of cache.
Clearing the npm cache in React or React Native projects
The React framework offers a seamless development experience by using multiple caching mechanisms in order to minimize the recompiling and loading time of applications.
However, it sometimes happens that one of these caches doesn't work as intended and doesn't pick up the latest changes made to the application's code or to the list of installed packages it relies on.
To fix this problem, you can restart your React Native application with a clean cache using the following command:
$ npm start -- --reset-cache
Run in Warp
Where the -- argument is used to forward the --reset-cache option to the command executed by the npm start script.
If this command doesn't work, you can use the following commands to:
1. Clear the list of files and directories watched by the watchman daemon.
$ watchman watch-del-all
Run in Warp
2. Remove the cache directories created by React Native and Metro.
$ rm -rf $TMPDIR/react-native-packager-cache-*
$ rm -rf $TMPDIR/metro-bundler-cache-*
Run in Warp
3. Remove the node_modules directory, clear the npm cache, and reinstall the npm packages.
$ rm -rf node_modules
$ npm cache clean --force
$ npm install
Run in Warp
Written by
Razvan Ludosanu
Founder, learnbackend.dev
Filed Under
Related Articles
List Open Ports in Linux
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Linux Chmod Command
Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.
POST JSON Data With Curl
How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
Switch Users In Linux
Learn how to switch between users, log in as another user, and execute commands as another user in Linux.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
Delete Files In Linux
Learn how to selectively delete files in Linux based on patterns and properties using the rm command.
Find Files In Linux
Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.
Copy Files In Linux
Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.