node-fs-extra: remove() doesn't delete a subfolder inside my project folder. What is wrong here ?

  • Operating System: Win 10 64 bit
  • Node.js version: 8.7.0
  • fs-extra version: 5.0.0

I am trying to delete a non-empty subfolder which is inside my project directory but i can’t seem to delete it with fs.remove(folderPath). The code runs with no errors but the folder is still there and i can’t even delete it manually unless i first empty the folder and delete all the files in there. I get a permission related error when i try to directly delete the folder even though i am the owner/admin. Could it be a permissions related issue ?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18

Commits related to this issue

Most upvoted comments

I’m seeing a similar problem on Windows. Every now and again in the test suite, it fails to remove a directory because it claims the directory is not empty. But when the process completes, the directory is gone. So could it be that there’s a race condition or that it’s a false warning?

Error: ENOTEMPTY: directory not empty, rmdir ...
at Object.fs.rmdirSync (fs.js:846:18)
at rmkidsSync (node_modules\fs-extra\lib\remove\rimraf.js:304:27)

I don’t even have words. So infinite loop it is.

I find it more likely that the fault is with node/v8 rather than windows. I looked into it for a bit but my understanding of node’s codebase it too bad to find anything in there. As per MSDN: The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed. and thus provide an alternate interface for deleting the folder content as well.

@RyanZim Yes, it does seem to be a problem with rimraf. That’s where it always dies.

I get something that looks like this:

Error: EBUSY: resource busy or locked, rmdir 'C:\projects\antora-odh8j\packages\cli\test\work'
  at Object.fs.rmdirSync (fs.js:846:18)
  at rmdirSync (node_modules\fs-extra\lib\remove\rimraf.js:276:13)
  at Object.rimrafSync (node_modules\fs-extra\lib\remove\rimraf.js:252:7)
  at Context.after (packages\cli\test\cli-test.js:79:10)

I’ve even tried rimraf directly and saw no improvement.

I have been very careful to ensure that no files or directories are locked. Windows just seems to be very unreliable at removing directories.

My only solution has been to use an infinite loop until Windows decides it actually wants to do what it was asked to do.