Delete node_modules from SPFx solution (rimraf)

In this SharePoint tutorial, we will discuss how to delete node_modules from SharePoint Framework (SPFx) solutions. We will see here, how to use rimraf cmdlet to delete the node_modules.

Here we will see different ways to delete the node_modules foler.

By default, when you will create an SPFx solution, it will add the node_modules which is very big in size. If you will try to delete it, it will take lots of time.

It will unnecessary take your space, because the folder is very big.

You can see when I try to delete, it will take a lot of time if to calculate the space.

Delete node_modules

The node_modules will have more than 15 lakhs files and it will take time to delete. (Got an approx count while trying to zip the folder using winzip.) And if you will zip the folder, it will be more than 250 MB.

What is rimraf

In an node based project, we can use rimraf to clean up the installed node package files. In a windows machine, becuase of the nested subfolder’s length, we can not delete and it will give you error.

The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or try renaming to shorter name(s) before attempting this operation.

So here it is rimraf. This will help us to delete the folder and nested subfolders.

Delete node_modules

First, we need to install rimraf in the windows machine. For this, run the below command:

Delete node_modules

You can see the install rimraf command like below:

install rimraf
install rimraf

Once we installed rimraf, we can run the rimraf command to delete the node_modules folder.

Navigate to the folder and run the below command:

rimraf node_modules


D:\Project\SPFxProfiles_07_10>rimraf node_modules

Here, the node_modules folder presented inside the SPFxProfiles_07_10 folder.

rimraf node_modules
rimraf node_modules

Once you execute the command, the node_modules folder will get deleted.

Delete node_modules from VS Code

Apart from the above method, we can also delete node_modules from visual studio code (vs code).

Open the SPFx solution using visual studio code and then right-click on node_modules and then click on Delete like below. It will take some time and it will delete the folder.

Delete node_modules from VS Code
Delete node_modules from VS Code

Delete node_modules from winrar

We can also delete node_modules folder from winrar. It will take approx less time.

Right click on the node_modules folder, then click on Add to archive… like below:

Delete node_modules from winrar
Delete node_modules from winrar

Then select Delete files after archiving checkbox option from the Archiving options like below:

how to Delete node modules from winrar

It will create a zip file and then it will delete the node_modules folder.

Later you can delete the zip file, it will be just over 250 MB that will not take more time.

You may like the following SharePoint framework tutorials:

In this tutorial, we learned:

  • What is rimraf
  • How to install rimraf in windows machine
  • How to delete node_modules using rimraf
  • Delete node_modules from VS Code
  • Delete node_modules from winrar