Error: while installing http-server on MacOS Mojave 10.14.2


(SYAMLAL M S) #1

What I Wanted to Do

I was trying to install http-server with sudo npm install --global http-server

What Happened Instead

endup with error!

Reproduction Steps

sudo npm install --global http-server

Tried on MacOS Mojave 10.14.2

Details

2019-02-03T06_09_33_044Z-debug.log (2.1 KB)

Platform Info

$ npm --versions
<!-- 
{ 'angular-phonecat': '0.0.0',
  npm: '6.7.0',
  ares: '1.13.0',
  cldr: '31.0.1',
  http_parser: '2.7.0',
  icu: '59.1',
  modules: '59',
  nghttp2: '1.25.0',
  node: '9.0.0',
  openssl: '1.0.2l',
  tz: '2017b',
  unicode: '9.0',
  uv: '1.15.0',
  v8: '6.2.414.32-node.8',
  zlib: '1.2.11' }
 -->
$ node -p process.platform
<!-- darwin -->

(John Gee) #2
  1. There isn’t much in the log. Were there errors displayed on the command line? Perhaps EISDIR and ENOENT?

  2. This isn’t the underlying issue, but you are running an old version of node (9.0.0). The LTS version is now 10.15.1.

  3. I reproduced a problem with same version of node and npm as you, but only when I used sudo. If this is your own computer, I recommend taking ownership of the directories npm uses so you do not need to use sudo. (You’ll need to redo this after installing using the installer from nodejs.org, which will install node and npm owned by root.)

As it happens, I wrote up some instructions earlier today:


(SYAMLAL M S) #3

It happened in the command line.

Btw, I’m unable to upgrade node as well. I’m getting similar error when trying below command:

npm install -g n


(John Gee) #4

(I think this is now a support question and not a bug in npm.)

I know n well, so I’ll walk you through step by step. If you get an error, please copy and post the error messages you see. (These steps are verbose but simple. If you want to install to your home directory instead, there are actually less steps!)

# Take ownership of directories used for node and npm
sudo chown -R $(whoami) /usr/local/bin
sudo chown -R $(whoami) /usr/local/lib
sudo chown -R $(whoami) /usr/local/share
sudo chown -R $(whoami) /usr/local/include
# install n (WITHOUT SUDO)
npm install --global n

Ok so far? Now upgrade node to LTS version:

# Create and take ownership of directory used by n
sudo mkdir -p /usr/local/n
sudo chown -R $(whoami) /usr/local/n
# install lts version of node (WITHOUT SUDO)
n lts

Ok so far? Installing node may have reinstalled an older version of npm, so let’s get the latest version. And then try your original install too!

npm install --global npm@latest
npm install --global http-server

Ok so far? From now on you do not need to use sudo when changing node versions using n, or when installing global npm modules.


npm minor updates - a thought
[crash] npm ERR! cb() never called!
(SYAMLAL M S) #5

Thank you for taking me through step by step. It really worked.

Also changing the tag to support.


(John Gee) #6

Hurrah! Thanks for confirming. (And for changing category.)