How to Delete Node Modules in VSCode?

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

Methods on How to Delete Node Modules Folder in VSCode

1: Using the Right-Click Menu

You can delete the node modules in VSCode by right-clicking on the node module folder.

  1. Open your project in VSCode.

  2. In the VSCode explorer, locate the node_modules folder.

  3. Right-click on the node_modules folder.

  4. Click on “Delete” to delete the folder.

    remove node module by right clicking

💡

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.

2: Using Terminal for Deletion

To delete node modules using the terminal, follow these steps:

  1. Open Integrated Terminal: Use Ctrl+Backtick(`) (or Cmd+Backtick(`) on Mac) to open the integrated terminal in VSCode.

  2. Navigate to Your Project: Use the cd command to navigate to your project directory – If you need to.

  3. Run the Deletion Command: Enter the command rm -rf node_modules and press Enter.

    rm rf command in terminal

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’”

rm rf node module command not working

💡

Remember, using the terminal for deletion follows the same principle: it wipes out the node_modules folder and requires a subsequent npm install to reinstall packages.

If you want to remove or uninstall individual packages, read on: How To Uninstall an NPM Package?

FAQs

  1. Why should I delete node modules in VSCode? Deleting unnecessary node modules can free up disk space and make your project more manageable.

    It’s especially helpful when sharing your code with others or when using version control systems like Git.
  2. Do I need to reinstall packages after deleting node modules? Yes, deleting the node_modules folder removes all installed packages. You’ll need to run npm install or yarn install again to restore them.
  3. What is the purpose of adding 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.
  4. Is there a shortcut to open the integrated terminal in VSCode? Yes, you can open the integrated terminal in VSCode by pressing Ctrl+Backtick (or Cmd+Backtick on Mac).