I encountered the following error when I tried to install some new packages using npm install
. It happened when I did npm install a-new-package --save
and then delete package-lock.json file afterwards to refresh everything.
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/memphismeng/Documents/React Programming/Foot-in-The-Door/mobile/fitd/node_modules/@babel/plugin-proposal-decorators
npm ERR! dest /Users/memphismeng/Documents/React Programming/Foot-in-The-Door/mobile/fitd/node_modules/@babel/.plugin-proposal-decorators-ysLLPQFw
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/memphismeng/Documents/React Programming/Foot-in-The-Door/mobile/fitd/node_modules/@babel/plugin-proposal-decorators' -> '/Users/memphismeng/Documents/React Programming/Foot-in-The-Door/mobile/fitd/node_modules/@babel/.plugin-proposal-decorators-ysLLPQFw'
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/memphismeng/.npm/_logs/2021-06-15T18_07_01_162Z-debug.log
What went wrong? I also tried npm audit fix --legacy-peer-deps
but it didn't work.
May be deleting node_modules
folder and package-lock.json
file and then reinstalling npm
would resolve your issue.
So, consider the following commands to apply the above operations:
npm remove node_modules
npm remove package-lock.json
npm install
I had the same problem while having a slow and unreliable Internet connection. I created this script that can be run with bash
that fixes all of the interrupted installs:
#!/bin/bash
set -e
while true; do
log="$HOME/.npm/_logs/`ls $HOME/.npm/_logs/ | tail -n 1`"
echo "log: $log"
for path in `cat "$log" | grep 'ENOTEMPTY' | grep -oE "[^']+node_modules[^']+"`; do
echo "removing $path"
rm -rf "$path"
done
if npm install; then
break
fi
done
Basically, I use the approach from https://stackoverflow.com/a/69668434/1320237 but I just had too much do deal with manually.
Note: While it looks to me like it has a O(n * n)
run time, it might have a O(n)
download time for n = number of packages
. So it is useful for slow Internet. You might be faster to just delete the node_modules
directory if your Internet connection is fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With