If you're facing issues with removing deeply nested node_modules
folders on Windows due to path length limitations, here are several methods to help you resolve the issue.
The rimraf
package is a widely used solution to remove directories with long path names on any platform.
Update, if you have npm v5, use nxp:
npx rimraf --glob **/node_modules
Otherwise install RimRaf:
npm install -g rimraf
rimraf --glob node_modules
And in the project folder delete the node_modules folder with:
If you want to recursively delete:
rimraf --glob .\**\node_modules
Please save yourself the need to read most of these answers and just use npx rather than trying to install rimraf globally. You can run a single command and always have the most recent version with none of the issues seen here.
npx rimraf ./**/node_modules
rm -r node_modules
I think this was not mentioned before. but the best way to delete unwanted node_modules is to install an utility called npmkill
.
You can install as globally
npm i -g npkill
Then simply call it on a folder directly from your terminal
npkill
or alternatively, you can directly use it without installation by writing:
npx npkill
You will then be presented with a list of projects, and by hitting space bar you can delete their node_modules
.
- Install the
remove-node-modules
globally
npm install -g remove-node-modules
- cd to root and
remove-node-modules
- or
remove-node-modules path/to/folder