Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid path error in windows #251

Closed
frbuceta opened this issue Jan 18, 2023 · 17 comments
Closed

Invalid path error in windows #251

frbuceta opened this issue Jan 18, 2023 · 17 comments

Comments

@frbuceta
Copy link

Rimraf has started to give me this error since I upgraded to the latest version. Any idea what could be happening?

Error: Illegal characters in path.
    at pathArg (C:\projects\loopback-next-x2uk1\packages\build\node_modules\rimraf\dist\cjs\src\path-arg.js:45:33)
    at C:\projects\loopback-next-x2uk1\packages\build\node_modules\rimraf\dist\cjs\src\index.js:45:40
    at C:\projects\loopback-next-x2uk1\packages\build\bin\run-clean.js:49:28
    at Array.forEach (<anonymous>)
    at run (C:\projects\loopback-next-x2uk1\packages\build\bin\run-clean.js:38:16)
    at Object.<anonymous> (C:\projects\loopback-next-x2uk1\packages\build\bin\run-clean.js:57:30)
    at Module._compile (node:internal/modules/cjs/loader:[115](https://ci.appveyor.com/project/strongloop/loopback-next-x2uk1/builds/45972045#L115)9:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  path: 'C:\\projects\\loopback-next-x2uk1\\sandbox\\sandbox-app\\*.tsbuildinfo',
  code: 'EINVAL'
}
@isaacs
Copy link
Owner

isaacs commented Jan 18, 2023

Perhaps you are passing in glob characters, like *? That's no longer supported in v4.

@stevebeauge
Copy link

Perhaps you are passing in glob characters, like *? That's no longer supported in v4.

glob pattern was a great feature of rimraf. I miss it a lot. Wonder if there's a chance to get it back

@christian-bromann
Copy link

What was the intention to remove glob support? What alternative would you suggest?

@kristian
Copy link

Unfortunately also our code is hard breaking since glob support was removed in version 4, especially because we also used it to spare some directories from deletion, using the { glob: { ignore: ..., nodir: true } option. Is there a alternative? Like a helper or pattern so we can continue using glob?

@isaacs
Copy link
Owner

isaacs commented Jan 19, 2023

glob pattern was a great feature of rimraf. I miss it a lot. Wonder if there's a chance to get it back

Yeah, people seem to really miss it. It's a sad fact of open source that you mostly only hear from people when something bothers them, so over the years, I'd gotten the (perhaps mistaken!) impression that the automatic globbing was a big problem, because I only heard about it when it caused issues.

But maybe now that it's removed, and I'm hearing about the issues that it causes to remove it. Life is funny that way.

So yes, given the responses here, there is a chance to get it back, but I need to finish the rewrite of glob v9 first. It's mostly there, just have to work out a pathological performance issue. (Oops, I said "just". It might "just" require completely rethinking the v9 approach, but I think there's probably a clever way through it.) Once that's done, it'll have a much less dated API, more resilience in the face of various filesystem issues, and have speed on par with the other implementations that have been developed in the many years since node-glob was first written.

In the meantime, you can use glob itself directly quite easily:

// rimraf-glob.cjs
const glob = require('glob')
const rimraf = require('rimraf') 
const rimrafWithGlob = async (pattern, rimrafOptions = {}, globOptions = {}) =>
  new Promise((res, rej) => {
    glob(pattern, globOptions, (err, results) => err ? rej(err) : res(rimraf(results, rimrafOptions)))
  })

if (require.main === module) {
  Promise.all(process.argv.slice(2).map(async (p) => rimrafWithGlob(p))
}

@isaacs
Copy link
Owner

isaacs commented Jan 19, 2023

Oh, and a bunch of tests are failing on Windows, so that's gonna have to be fixed, too.

Feel free to follow along at: isaacs/node-glob#489

@klh
Copy link

klh commented Jan 19, 2023

thanks for the effort isaacs

@kai-dorschner-twinsity
Copy link

kai-dorschner-twinsity commented Jan 20, 2023

Thanks for your effort too, I love and use this library for many years! :)
Does anyone know a way of patching glob into the CLI command of v4? Or is the only way to go back to v3? I use it when npm fucks up things in workspaces and I want to start from the get go via rimraf ./**/node_modules

@isaacs
Copy link
Owner

isaacs commented Jan 31, 2023

@kai-dorschner-twinsity Just npm i rimraf@3 to get version 3. It's a SemVer major version, the only way you would have gotten it unexpectedly would have been a fresh install in a new project, or an unsafe dependency range like "rimraf": "*" in package.json.

In the meantime, if you want to use it with globs, just npm install glob, and write a script like I showed in the comment above. #251 (comment)

Save that as rimraf-glob.cjs and instead of having your script be "whatever": "rimraf some/*/glob/+(pa|ths)" or rimraf ./**/node_modules on the shell, make it "whatever": "node rimraf-glob.cjs some/*/glob/+(pa|ths)" or node rimraf-glob.cjs ./**/node_modules on the shell.

Or, if you're using Bash version 4 or greater, you can add shopt -s globstar ; shopt -s extglob to your ~/.bashrc file, and then rimraf ./**/node_modules will work on the shell, or even rm -rf ./**/node_modules, because the shell will expand the globs for you before rimraf or rm even sees them. For example:

$ node -e 'console.log(process.argv.slice(1))' test/+(bin|readdir)*
[ 'test/bin.js', 'test/readdir-or-error.js' ]

Of course, that'll probably never work on Powershell or cmd.exe, but installing glob and using your own script would work fine on any platform.

@isaacs
Copy link
Owner

isaacs commented Feb 27, 2023

dupe #249

@isaacs isaacs closed this as completed Feb 27, 2023
@isaacs
Copy link
Owner

isaacs commented Mar 3, 2023

Landed on 4.2.0

@kristian
Copy link

kristian commented Mar 3, 2023

Perfect timing, thanks so much @isaacs! We are about to bump our deps atm. 💯

@isaacs
Copy link
Owner

isaacs commented Mar 3, 2023

Perfect timing, thanks so much @isaacs! We are about to bump our deps atm. 💯

Keep in mind, you will have to add --glob to the command line or {glob:true} in the options if upgrading from v3.

@kristian
Copy link

kristian commented Mar 3, 2023

Keep in mind, you will have to add --glob to the command line or {glob:true} in the options if upgrading from v3.

Duly noted, we anyways in most cases passed glob options in form of { glob: { ... } } to rimraf, meaning glob support is enabled "by default". However I will check the cases where we are not passing any glob options and pass true instead, to make sure globbing support is enabled. Thanks again for the quick turnaround in re-introducing that feature. Highly appreciated.

@isaacs
Copy link
Owner

isaacs commented Mar 3, 2023

Yeah, passing glob:{...options} also works

@kristian
Copy link

kristian commented Mar 3, 2023

Yeah, passing glob:{...options} also works

Yes, just validated and all works as expected. Thanks again for following up to this one @isaacs! 👍

@Jack-Works
Copy link

maybe a better error message? it doesn't obvious that "Error: Illegal characters in path." means I should set "{ glob: true }"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants