How To Delete Node_Modules Folder : NPM

Ever used NPM(Node package manager) to install packages for your client side applications? If yes then you must have noticed node_modules folder that is created once you run npm install. Did you ever try to delete that folder, with most of the cases you will be stopped by a windows message. Let's see what's that and what's workaround for that.


delete node_modules folder from windows using rimraf



Issue In Deleting Node_Modules Folder


When a module is installed in a folder using NPM, then files related to that module are added into node_modules folder. But the problem is that it creates multiple hierarchical folder chain which leads
windows to show below error

unable to delete node_modules folder in windows


Source Path Too Long.
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.

How To Remove Node_Modules Folder ?


To remove the node_modules folder, first we have to open the folder in command prompt. To do this just open your folder in which your node_modules folder is present. Then in the address bar just type in cmd and press enter. That's the easiest way to open cmd, thank us later if you didn't know. :P

Now the command prompt window will open up with your folder path. We will use rimraf package from npm to delete the node_modules folder. To install this package you need to type in below command in command window.


npm install rimraf -g

This will install rimraf in your machine globally. So that you need not to in stall it again ever. rimraf is used to delete the folders and is very popular among the npm users.

Now after installing rimraf, just type in below command to remove any specific folder. In our case it's node_modules

rimraf node_modules

After running this command you will notice that the folder gets deleted in a while. You need to wait little longer if you had more than 20 packages installed. So be patient.

Watch the video below, this will help you better



Try this and let us know if it helped.

Happy Learning!!!

Comments

  1. You can easily delete or copy any kind of files, downloads or folders with Long Path Tool.

    ReplyDelete
    Replies
    1. Yes, that's a great tool but that requires a setup download and its installation. We prefer rimraf cause it's convenient and more specific to this problem.

      Delete

Post a Comment

Hey there, liked our post. Let us know.

Please don't put promotional links. It doesn't look nice :)

Popular posts from this blog

Create Android Apps - Getting Started

Polymorphism in Kotlin With Example