Error: Illegal characters in path in npm rimraf
Asked Answered
P

1

18

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'
}

Pasturage answered 30/1, 2023 at 6:57 Comment(1)
no glob starting from v4, in Windows you can use powershell, see https://mcmap.net/q/94531/-rimraf-powershell-script-glob-syntax/1207195Mistral
C
31

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.

Cubiculum answered 1/2, 2023 at 10:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.