grunt-contrib-clean: Keep getting ENOTEMPTY error. Unable to delete directories.

I am having trouble deleting my dirs when running grunt-contrib-clean I get this output

Running "clean:dist" (clean) task
Verifying property clean.dist exists in config...OK
Files: .tmp, dist -> dist
Options: force, no-write=false
Cleaning .tmp...ERROR
Warning: Unable to delete ".tmp" file (ENOTEMPTY, directory not empty 'C:\Path\.tmp'). Use --force to continue.

Aborted due to warnings.

This is my grunt config:

clean: {
    options: { force: true },
    dist: ['.tmp', 'dist']
},

Is there anything that I can do to fix this issue?

System information

  • Windows 7
  • Node version: 0.10.17
  • Grunt version: 0.4.1
  • Task version: 0.5.0

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 28 (1 by maintainers)

Most upvoted comments

I had the same problem; but it seems it was due to the fact I had an explorer window opened in the directory I was trying to delete. Could it be that you are in the same situation ?

This is working for me:

    clean: {
        dist: distDir + '/**/*.*'
    },

As long as you don’t mind the directories sticking around.

In Windows this is related to windows path 255 character limit. When you have node modules that are nested deeply the windows path exceeds its limit. If you were to delete the directory by hand in the explorer window you would see the exception triggered and you get a dialog that says something like “the path is too long do you want to proceed with permanently deleting this”. When fired from grunt this exception issues an error and grunt stops.

I’ve been able to somewhat mitigate this issue by identifying problematic node modules and deleting the node_modules directory in those first.

clean: { dist: { src: [‘dist/problem_module_1/node_modules/’,‘dist/problem_module_2/node_modules/’, ‘dist/’], options: { force:true } } }

I have the same problem and I think the problem was Windows 7. The same gulpfile on Windows 8 works as expected.

I was Dropbox in my case.