'ENOTEMPTY: directory not empty, rename '' -> '' (JavaScript + NPM + Ubuntu server)

Alright, so I've been making a bot for a popular Teamspeak-like program called discord. I'm running the bot on an Ubuntu server, and use NPM install to install various modules.

Currently, the local version of the bot works fine, but on Ubuntu I can't seem to do "sudo npm install urban" (Urban being the only module I'm having problems with - https://www.npmjs.com/package/urban )

The error I get is

npm ERR! Linux 4.2.0-27-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "urban"
npm ERR! node v5.6.0
npm ERR! npm  v3.6.0
npm ERR! path /var/www/chatbot/node_modules/urban
npm ERR! code ENOTEMPTY
npm ERR! errno -39
npm ERR! syscall rename
npm ERR! ENOTEMPTY: directory not empty, rename '/var/www/chatbot/node_modules/urban' -> '/var/www/chatbot/node_modules/.urban.DELETE'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/chatbot/npm-debug.log

When I cd to the node_modules folder and do ls, there isn't even an urban folder I could work with.

I am relatively new to programming, so I'm sorry if I missed anything, I'll gladly add more information if needed. Thanks in advance, guys.



Solution 1:[1]

I simply deleted the node_modules folder and ran npm install again ;)

Solution 2:[2]

I just deleted the folder node_modules/.request.DELETE/ and then ran npm install and everything seems to be working properly.

Solution 3:[3]

This is because there is a hidden folder with a .DELETE extension present in your node_modules folder, Just follow these steps,

Open Terminal (click Go > Utilities and double-click the Terminal app)

Now copy, and paste both lines listed below into Terminal one at a time, and press Return after each line:

defaults write com.apple.finder AppleShowAllFiles YES

killall Finder

Mac will now show all the hidden folders, delete your module folder with .DELETE extension and try

npm install <packagename>

Use sudo if errors

sudo npm install <package>

That's it. You should be able to install.

Solution 4:[4]

In my case node process was locking the folder. I used

lsof | grep DELETE

to find this out. So I just stopped webpack-dev-server that was running the process and continued with

npm install

So check what process is locking the file/folder, then decide how to fix this

Solution 5:[5]

I was facing the issue while running

ng build --watch

but after trying

npm install

Fixed!

Solution 6:[6]

I faced the same problem. Actually there is a file or folder with .DELETE extension in your node_modules folder.

You can force delete the file or folder with .DELETE extension. Or if you are working on your local machine, issue can be fixed by delete the node_modules folder and reinstalling the packages by following command

npm install

Solution 7:[7]

I ran into this issue as well. Deleting the nodes_modules folder made it work immediately after but the error kept coming back. It turned out I had the directory open!! Doh!

Solution 8:[8]

You can use npm ci to perform a clean install.

Internally, It will wipe out node_modules and install all packages again. But it is faster than npm install if you already have your package.lock.json

As per the documentation,

npm ci will be significantly faster when:

There is a package-lock.json or npm-shrinkwrap.json file.
The node_modules folder is missing or empty.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephane
Solution 2
Solution 3 Remi Guan
Solution 4 p.boiko
Solution 5 Shobhit Verma
Solution 6 Azhar Zafar
Solution 7
Solution 8 Rahul Pol