Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/tmp'

What I Wanted to Do

m$ sudo npm install -g n

What Happened Instead

Unhandled rejection Error: EISDIR: illegal operation on a directory, open β€˜/Users/me/.npm/_cacache/tmp’

βΈ¨β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘βΈ© β § rollbackFailedOptional: verb npm-session 48204fc8f328be64

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:

npm ERR! <https://npm.community>

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/me/.npm/_logs/2019-02-25T23_40_13_067Z-debug.log

Reproduction Steps

Details

0 info it worked if it ends with ok

1 verbose cli [ β€˜/Users/me/.nvm/versions/node/v8.11.3/bin/node’,

1 verbose cli β€˜/Users/me/.nvm/versions/node/v8.11.3/bin/npm’,

1 verbose cli β€˜install’,

1 verbose cli β€˜-g’,

1 verbose cli β€˜n’ ]

2 info using npm@6.8.0

3 info using node@v8.11.3

4 verbose npm-session 48204fc8f328be64

5 silly install loadCurrentTree

6 silly install readGlobalPackageData

7 timing npm Completed in 238841ms

8 error cb() never called!

9 error This is an error with npm itself. Please report this error at:

10 error <https://npm.community>

Platform Info

$ npm --versions
{ 'search-electrode-app': '8.7.0-a',
  npm: '6.8.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.3',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

Long answer with lots of info and links.

The quick work-around is to reset the ownership in the folder you mentioned, before trying the install again:

sudo chown -R $(whoami) ~/.npm

The underlying issue is npm leaving behind some files owned by root, and the canonical open bug is:

A nice way of avoiding the problem is do not use sudo with global installs (or with node installs). If you are planning to install n and use it to install node to /usr/local rather than to your home folder, I wrote up some longer instructions specifically for n. See this comment:

And lastly, I recently promoted my own fork of n if a more modern spin on the same approach is of interest:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.