cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] install global typescript got error: npm ERR! ENOTEMPTY: directory not empty

Open aladdin-add opened this issue 4 years ago • 5 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

➜  create-config git:(feat/eslint-init) npm i typescript -g
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /Users/weiran/.npm-global/lib/node_modules/typescript
npm ERR! dest /Users/weiran/.npm-global/lib/node_modules/.typescript-ffKYZhoU
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/Users/weiran/.npm-global/lib/node_modules/typescript' -> '/Users/weiran/.npm-global/lib/node_modules/.typescript-ffKYZhoU'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/weiran/.npm/_logs/2021-11-26T07_32_40_759Z-debug.log

Expected Behavior

global typescript installed without error.

Steps To Reproduce

No response

Environment

  • npm: 8.1.4
  • Node: v17.0.1
  • OS: macOS 12.1
  • platform:
  • npm config:
; copy and paste output from `npm config ls` here
; "user" config from /Users/weiran/.npmrc

//git.dian.so/api/v4/packages/npm/:_authToken = (protected) 
//npm.xiaodiankeji.net/:_authToken = (protected) 
//registry.npmjs.org/:_authToken = (protected) 
home = "https://npm.taobao.org" 
http-proxy = "http://127.0.0.1:8118" 
https-proxy = "http://127.0.0.1:8118/" 
init-author-name = "weiran" 
; package-lock = true ; overridden by project
prefix = "/Users/weiran/.npm-global" 
proxy = "http://127.0.0.1:8118/" 

; "project" config from /Users/weiran/repo/github/create-config/.npmrc

package-lock = false 

; node bin location = /usr/local/bin/node
; cwd = /Users/weiran/repo/github/create-config
; HOME = /Users/weiran
; Run `npm config ls -l` to show all defaults.

aladdin-add avatar Nov 26 '21 07:11 aladdin-add

update: it was fixed after run rm -rf /Users/weiran/.npm-global/lib/node_modules/typescript

aladdin-add avatar Dec 02 '21 05:12 aladdin-add

I'm experiencing similar with many many packages. It is not practical to remove them all.

E: Removing and recreating package-lock.json (+ removing node_modules) helped but that's a nasty workaround since you loose the control over exact versions of the packages.

villesau avatar Mar 22 '22 11:03 villesau

After removing individual packages form node_modules, I ended up removing the whole node_modules folder (but not deleting package-lock.json), and got the issue fixed.. running npm install completed without errors 🤷

AleksandarSavic95 avatar Apr 11 '22 20:04 AleksandarSavic95

We are experiencing this on shared workers in CI where npm install -g ts-node is aborted mid-install and then the global node_modules directory is poisoned and NPM can't seem to recover on it's own. We even added a test which tries to find $(npm root -g)/ts-node directories which aren't complete installs and delete them before running npm and it's not helping.

Abort: https://buildkite.com/elastic/kibana-pull-request/builds/55377#0181cf7a-d891-4757-a605-3b7763e0c735 Subsequent failure: https://buildkite.com/elastic/kibana-pull-request/builds/55379#0181cf7b-bf0e-4f9e-aecf-73c9d4d4e684 Our retry script: https://github.com/elastic/kibana/blob/0bc5822be3b18ca57a44afbd030060f0508ac51d/.buildkite/scripts/common/util.sh#L145-L170

spalger avatar Jul 05 '22 18:07 spalger

We also have such issues in our user base (smart home software iobroker, >70k installs) for some users ...

Yes it seems that npm in some cases do not correctly clean up their temporary directories and then on next run it errors because the directory already exists.

The fix for us is for now to have a "one liner shell script" that finds and deletes all these wrong directories ... But a fix would be better :-) BUT the issues comes back sometimes for these users. And we have other users that do not have such issues at all

Why does npm not simply delete the dir itself before reusing it?

Apollon77 avatar Sep 04 '22 22:09 Apollon77

I do confirm what Apollon77 wrote, I am heavily impacted by this as well, running iobroker in a FreeBSD 13.1 jail on TrueNAS with npm 8.19.1. Node module upgrades from the iobroker gui are impossible and in cli I have to clean the node_modules folder manually after each single module upgrade by deleting all folders in node_modules that are starting with a . (dot), using below command.

find . -type d -path '/.' -exec rm -rf {} ;

It's really annoying.

softy66 avatar Oct 02 '22 14:10 softy66

The mentioned one liner:

for i in $(find /opt/iobroker/node_modules -type d -iname ".*-????????" ! -iname ".local-chromium"); do rm -rf ${i%}; done

Grothesk242 avatar Oct 02 '22 20:10 Grothesk242

I'm having this same issue with any globally installed package

shadow1349 avatar Mar 21 '23 22:03 shadow1349