npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.54k stars 3.2k forks source link

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

Open aladdin-add opened 3 years ago

aladdin-add commented 3 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

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

//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 commented 3 years ago

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

villesau commented 2 years ago

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.

AleksandarSavic95 commented 2 years ago

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 🤷

spalger commented 2 years ago

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

Apollon77 commented 2 years ago

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?

softy66 commented 2 years ago

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.

Grothesk242 commented 2 years ago

The mentioned one liner:

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

shadow1349 commented 1 year ago

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