Frontend application projects often come with a hefty luggage known as the node_modules
folder.
While these modules are essential for the project’s functionality, they can sometimes become a burden, taking up significant disk space or even become corrupted as it may contain outdated or conflicting data.
In this guide, we will look at two methods on how to delete the node modules in Visual Studio Code (VSCode).
You can delete the node modules in VSCode by right-clicking on the node module folder.
Open your project in VSCode.
In the VSCode explorer, locate the node_modules
folder.
Right-click on the node_modules
folder.
Click on “Delete” to delete the folder.
💡
This action will remove the entire
node_modules
folder along with all installed packages.Keep in mind that you’ll need to reinstall these packages later using
npm install
.
To delete node modules using the terminal, follow these steps:
Open Integrated Terminal: Use Ctrl+Backtick(`)
(or Cmd+Backtick(`)
on Mac) to open the integrated terminal in VSCode.
Navigate to Your Project: Use the cd
command to navigate to your project directory – If you need to.
Run the Deletion Command: Enter the command rm -rf node_modules
and press Enter.
If you are a Windows user, and you encounter an error while running rm -rf node_modules
as shown below, you can read more on how to fix it: How to Fix “Remove-Item: A parameter cannot be found that matches parameter name ‘rf’”
💡
Remember, using the terminal for deletion follows the same principle: it wipes out the
node_modules
folder and requires a subsequentnpm install
to reinstall packages.
If you want to remove or uninstall individual packages, read on: How To Uninstall an NPM Package?
node_modules
folder removes all installed packages. You’ll need to run npm install
or yarn install
again to restore them.node_modules
to .gitignore
? Adding node_modules
to .gitignore
prevents the folder from being tracked by Git, reducing repository size and preventing unnecessary versioning of external dependencies.Ctrl+Backtick
(or Cmd+Backtick
on Mac).