EISDIR error when updating Node from 8.10 on Mac

What I Wanted to Do

I wanted to update Node on my Mac (High Sierra 10.13.3) from v8.10.0 to latest stable version using Terminal. Using npm v6.9.0

What Happened Instead

The update failed producing a number of errors listed below.

Reproduction Steps

Open up Terminal
Type sudo npm install -g n

Details

Node version 8.10.0
NPM version 6.9.0
Using Mac HighSierraOS

Errors produced
`Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/jfinn/.npm/_cacache/tmp’

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/jfinn/.npm/_logs/2019-06-06T17_46_48_538Z-debug.log`

I tried using the following command based on a similar bug reported
sudo chown -R $(whoami) ~/.npm

however it produced the same results

Platform Info

Mac HighSierraOS

$ npm --versions
{ npm: '6.9.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.7.0',
  icu: '60.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.10.0',
  openssl: '1.0.2n',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.50',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

(If you can wait a day before trying fixes, someone might be interested in getting some debugging while you have a reproducible failure.)

A subset of the EISDIR issues are fixed by upgrading node, so this would be interesting to try, running same command but using node 10 without changing rest of your install:

npx -p node@10 -- sudo npm install -g n

(More certain work-arounds are deleting the .npm folder or using a different TMPDIR. I’ll reply again if needed.)

Thanks John. I tried using your suggestion with Node 10

npx -p node@10 -- sudo npm install -g n

but it has also failed. The error output shows:

Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/jfinn/.npm/_cacache/content-v2/sha512/a3'

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/jfinn/.npm/_logs/2019-06-06T21_14_20_128Z-debug.log
Install for node@10 failed with code 1

I also tried it with sudo at the front and it gave a similar but different error

Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/jfinn/.npm/_cacache/content-v2/sha512/a3/03'

Interesting. The EACCES permission denied is expected without sudo.

The EISDIR with sudo is unclear. If my conjecture in chownr issue 20 is correct, the EISDIR issue should no longer appear in Node 10.6 or later, based on this commit which removed the buggy but MacOS specific lchown implementation from lib/fs.js prior to the node 10.6 release.

@shadowspawn what exactly does npx -p node@10 do? The documentation says it installs the node binary, but the relevant code with the bug fix is in lib/fs.js - does npx install node 10 along with its js code or just the binary?

@jamesfinn180 could you try updating node first to the 10.* line (later than 10.6) and then try the ‘sudo …’ commands again? Since you can’t install ‘n’ you can’t use ‘n’ yet anyway.

  1. For interest, I tracked down a previous report mentioning tmp and perhaps coincidence, but was also trying to install n: [crash] npm ERR! cb() never called!

  2. @godmar npx is installing a package. I assume the third-party node package has the full context for node 10, but I don’t know enough about how node built-in modules are bundled to definitively answer your question:

  1. @jamesfinn180

I suggest try deleting the .npm cache folder with extreme prejudice then have another go at the install (take care with the rm command)

sudo rm -rf ~/.npm
sudo npm install -g n

(In the longer term I recommend avoiding the need for sudo with global installs, and you will have more options once you have n installed, but first we want to get you unblocked!)

My current working theory for the EISDIR error when running under sudo is:

  • MacOS-specific
  • node version < 10.6
  • npm/cli version >= 6.6.0 or later (that’s when chownr 1.1.1 was introduced)

PS: note that for those hapless MacOS users, the EISDIR error occurs on all directories for which npm changes the ownership to the $SUDO_UID user. Keep in mind that npm chowns some directories it shouldn’t chown (as per pacote 175).