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.
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.
First, we need to install rimraf in the windows machine. For this, run the below command:
You can see the install rimraf command like below:
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:
Here, the node_modules folder 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 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 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:
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.
You may like the following SharePoint framework tutorials:
- Create and deploy SharePoint Framework (SPFx) listview command set extension
- Create and Deploy SharePoint Framework (SPFx) extension field customizer
- SharePoint Framework (SPFx) Extensions Application Customizer Example
- The entry point for component has a dependency on “@microsoft/sp-http” that is not declared in the manifest react spfx
- Can’t load the application on this page. Use the browser Back button to retry while adding SPFx web part into Microsoft Teams
- Property welcome does not exist on type ‘JSX.IntrinsicElements’ in SPFx React
- How to Create Site Columns, Content Type and Custom List using SharePoint Framework
- SharePoint client-side web part configurable properties in Property Pane using spfx
- no gulpfile found error in spfx
- cannot find module jquery spfx
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
I am Bijay a Microsoft MVP (8 times – My MVP Profile) in SharePoint and have more than 15 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