ENOTEMPTY in Node.js — What It Means and How to Fix It
What the Node.js/npm error ENOTEMPTY means and how to resolve it.
Published October 26, 2026
ENOTEMPTY means you tried to remove a directory that still contains files.
What it means and why it happens
fs.rmdir only removes empty directories. Use fs.rm with recursive: true instead.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
Error: ENOTEMPTY: directory not empty, rmdir 'build'
Practical examples
Code that triggers it
fs.rmdirSync('build')The fix
fs.rmSync('build', { recursive: true, force: true })Async version
await fs.promises.rm('build', { recursive: true, force: true })Common mistakes
- Using rmdir for non-empty folders.
- Deleting the wrong path with recursive: true.
- Files still locked by other processes (Windows).
Key takeaways
- ENOTEMPTY: ENOTEMPTY means you tried to remove a directory that still contains files.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
rimraf still needed?
Not on modern Node; fs.rm covers it.
How do I find which line caused ENOTEMPTY?
The error message and stack trace show the file and line; start there and work backwards.