Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Illegal characters in path in npm rimraf

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/**

> [email protected] 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'
}

like image 254
Sanke Avatar asked Nov 21 '25 06:11

Sanke


1 Answers

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.

like image 135
Will Avatar answered Nov 22 '25 19:11

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!