How to remove node modules in react project with commands ?

If we are using yarn, We need to use the following commands in the terminal to remove the node modules and cleanup the cache

rm – Rf node_modules

yarn cache clean

yarn install

If we are using npm, We need to use the following commands in the terminal to remove the node modules and cleanup the cache

rm – Rf node_modules

npm cache clean –force

npm install

Breakdown of the Command “rm – Rf node_modules”

  • rm: The command used to remove (delete) files or directories.
  • -r (or -R): Recursive flag. It instructs the terminal to dig inside the folder and delete all nested files and subdirectories.
  • -f: Force flag. It bypasses any confirmation prompts and ignores non-existent files.
  • node_modules: The target folder holding your local Node.js package dependencies.

If we want delete package-lock.json or yarn.lock file then we need to use either

rm -rf node_modules package-lock.json

(or)

rm -rf node_modules yarn.lock


Discover more from Learners Store

Subscribe to get the latest posts sent to your email.

Leave a comment