Trying to update node

I’m trying to update node without having to install anything else. Per this, I tried to update node. The first command worked fine:
sudo npm cache clean -f

but the second command didn’t:
sudo npm install -g n

I thought npm would install fine but instead, I got the following error:
Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/hectordominguez-maceda/.npm/_cacache/index-v5/b0/67’
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/myname/.npm/_logs/2019-04-01T04_28_54_417Z-debug.log

Also attached is the error log. 2019-04-01T04_15_57_620Z-debug.log (513 Bytes)

Again, I wanted to run all of the following but only got to run up to the second line:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

$ npm --versions
6.9.0
<!-- paste output here -->
$ node -p process.platform
darwin
<!-- paste output here -->

Short answer

Run this to fix the ownership, then try your install again:


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

Long answer

If you actually read the long version and anything does not make sense, feel free to ask more questions. Covering a lot of ground!

  • there is an ownership bug causing the EISDIR error
  • installing node using n will install npm too, so if you want the latest npm you want to install it after installing node+npm using n. Your linked instructions do things in the wrong order.
  • It is good practice to avoid using sudo with npm, but this does require a little extra work. Your three main options are:
  1. change the ownership of the global install location
  2. change the location of the global install location to somewhere you own, by changing where you install node and npm (node version managers typically support this)
  3. change the location of the global install location to somewhere you own, by changing npm configuration

EISDIR

The long version and canonical bug is: Global installs (sudo npm i -g) fail on Mac after 6.5 upgrade. Works fine after 6.4.1 downgrade.

n and sudo

To avoid using sudo with n, you can either define N_PREFIX and install to your home folder, or change ownership. I personally prefer changing ownership like Homebrew on Mac does, and wrote up detailed instructions for that: Error: while installing http-server on MacOS Mojave 10.14.2

Facing the same issue as the OP.

I ran

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

and re-ran

sudo npm install -g n

and now get:

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/sridharkatakam/.npm/_cacache/index-v5/b0/67’

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/sridharkatakam/.npm/_logs/2019-05-16T23_07_58_473Z-debug.log
Sridhars-MacBook-Pro-3:uikit sridharkatakam$ sudo chown -R (whoami) ~/.npm Sridhars-MacBook-Pro-3:uikit sridharkatakam sudo npm install -g n
npm WARN tar EISDIR: illegal operation on a directory, open ‘/Users/sridharkatakam/.nvm/versions/node/v8.1.3/lib/node_modules/.staging/n-d55dfb03/bin’
Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/sridharkatakam/.npm/_cacache/content-v2/sha512/9b/14’

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/sridharkatakam/.npm/_logs/2019-05-16T23_09_29_266Z-debug.log

Resolved via

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

Source: https://stackoverflow.com/a/50639828/778809

1 Like

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