In this SharePoint tutorial, we will discuss how to delete node_modules from SharePoint Framework (SPFx) solutions. We will see how to use the rimraf cmdlet to do this.
Here, we will see different ways to delete the node_modules folder.
By default, when you create an SPFx solution, it adds the node_modules, which is very large. Trying to delete it will take a lot of time.
It will unnecessarily take your space because the folder is very big.
As you can see, when I try to delete, it takes a lot of time to calculate the space.
The node_modules will have more than 15,00,000 files, and it will take time to delete them. (I got an approximate count while trying to zip the folder using Winzip.) If you zip the folder, it will be more than 250 MB.
What is rimraf?
In a node-based project, we can use Rimraf to clean up the installed node package files. However, because of the nested subfolder’s length, we can not delete it on a Windows machine, and it will give you an error.
The source file name(s) are larger than the file system supports. Before attempting this operation, try moving to a location with a shorter path name or renaming to a shorter name(s).
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 below:
Once we have 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
Example:
D:\Project\SPFxProfiles_07_10>rimraf node_modules
Here, the node_modules folder is presented inside the SPFxProfiles_07_10 folder.
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, right-click on node_modules, and click on Delete, as shown below. It will take some time, but it will delete the folder.
Delete node_modules from winrar
We can also delete the 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:
Then select Delete files after archiving checkbox option from the Archiving options like below:
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.
In this tutorial, we learned:
- What is rimraf
- How to install rimraf in a windows machine
- How to delete node_modules using rimraf
- Delete node_modules from VS Code
- Delete node_modules from winrar
You may also like the following tutorials:
- SharePoint framework client web part example
- The api entry could not be loaded: node_modules/@microsoft/sp-webpart-workbench/lib/api/ in SharePoint Framework
- How to Configure Web Part Icon in SPFx
- Display SharePoint list items using SPFx
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com