How to Fix "Remove-Item: A parameter cannot be found that matches parameter name 'rf'"

If you’re a Window/PowerShell user, you may have encountered the following error message:

Remove-Item : A parameter cannot be found that matches parameter name 'rf'.
At line:1 char:4
+ rm -rf node_modules
+    ~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-Item], ParameterBindingException    
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.RemoveItem  
   Command

💡

I encounter this error when trying to remove node_modules folder from a “next.js” project using VSCode’s terminal.

This error occurs when you try to use the rm (or Remove-Item) command with the -rf flags to recursively force remove a directory or file.

However, PowerShell does not support the -rf flags like Unix-based terminals (e.g., Linux or macOS) do.

In this article, we will look at how to fix this error.

How to fix the “Remove-Item : A parameter cannot be found that matches parameter name ‘rf’” error

To fix the Remove-Item : A parameter cannot be found that matches parameter name 'rf' error, you need to use the Remove-Item cmdlet (as a replacement for rm) with the -Recurse and -Force parameters (as a replacement for -rf).

The Remove-Item is used to remove directories and files.

The -Recurse parameter, tells the command to remove the directory and all of its contents recursively, and the -Force parameter tells the command to force the removal without asking for confirmation.

Here’s the correct syntax:

Remove-Item -Path "directory_or_file_path" -Recurse -Force

Replace directory_or_file_path with the path to the directory or file that you want to remove.

For Example:

The following example shows how to use the Remove-Item cmdlet with the -Recurse and -Force parameters to recursively remove the node_modules directory:

Remove-Item -Path "node_modules" -Recurse -Force

This command will remove the node_modules directory and all of its contents without asking for confirmation.

Hope this helps? 🎉