13

I am getting an error while I tried to delete multiple directories using npm rimraf.

Error: Illegal characters in path

Command I run is rimraf **/lib/**

> ecommerce.ui@0.7.2 clean-libs
> rimraf **/lib/**

Error: Illegal characters in path.
    at pathArg (C:\Users\SUDARANGA\AppData\Roaming\nvm\v18.9.0\node_modules\rimraf\dist\cjs\src\path-arg.js:45:33)
    at C:\Users\SUDARANGA\AppData\Roaming\nvm\v18.9.0\node_modules\rimraf\dist\cjs\src\index.js:34:66       
    at Array.map (<anonymous>)
    at C:\Users\SUDARANGA\AppData\Roaming\nvm\v18.9.0\node_modules\rimraf\dist\cjs\src\index.js:34:28       
    at main (C:\Users\SUDARANGA\AppData\Roaming\nvm\v18.9.0\node_modules\rimraf\dist\cjs\src\bin.js:134:11) 
    at Object.<anonymous> (C:\Users\SUDARANGA\AppData\Roaming\nvm\v18.9.0\node_modules\rimraf\dist\cjs\src\bin.js:143:5)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12) {
  path: 'C:\\source\\Ecommerce.UI\\**\\lib\\**',
  code: 'EINVAL'
}

Sanke
  • 676
  • 2
  • 13
  • 30

1 Answers1

19

Version 4.0 of rimraf removed globbing support, but they restored globbing in version 4.2 (released March 2023).

If you're using rimraf from the command line (i.e. using it as an npm command and not using the JavaScript API), it's now behind a --glob flag:

rimraf --glob packages/**/*.tgz

If you're using the JavaScript API, you can use the glob option:

import { rimrafSync } from 'rimraf';

rimrafSync('/foo/*.bar', { glob: true });

If you can't use version 4.2, and you're using rimraf just from the command line, then I've found that del-cli seems to be a good cross-platform replacement.

Will
  • 2,086
  • 23
  • 30