Cache access bug

What I Wanted to Do

I was trying to get the latest packages installed on my machine and ran the following command:

sudo npm install -g n latest

I’m on OSX 10.14.5, mid-2014 Macbook Pro.

What Happened Instead

It appears that an illegal cache operation occurred. I received the following error message:

Unhandled rejection Error: EISDIR: illegal operation on a directory, open β€˜/Users/cbh/.npm/_cacache/content-v2/sha512/3f/99’
at Error (native)

Unhandled rejection Error: EISDIR: illegal operation on a directory, open β€˜/Users/user/.npm/_cacache/content-v2/sha512/33/9c’
at Error (native)

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/user/.npm/_logs/2019-05-30T10_37_40_000Z-debug.log

Reproduction Steps

Other than running a Mac and the above command, I know of nothing.

$ npm --versions

{ npm: β€˜6.9.0’,
ares: β€˜1.15.0’,
brotli: β€˜1.0.7’,
cldr: β€˜35.1’,
http_parser: β€˜2.8.0’,
icu: β€˜64.2’,
modules: β€˜64’,
napi: β€˜4’,
nghttp2: β€˜1.34.0’,
node: β€˜10.16.0’,
openssl: β€˜1.1.1b’,
tz: β€˜2019a’,
unicode: β€˜12.1’,
uv: β€˜1.28.0’,
v8: β€˜6.8.275.32-node.52’,
zlib: β€˜1.2.11’ }

$ node -p process.platform
darwin

Hi @erdos! There is an open issue with installing global packages using sudo leaving behind files with the wrong ownership.

The short version is run this to fix the ownership, then try your install again (assuming bash shell):

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

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.

Resetting the permissions will not make a difference if running the command as sudo fails. @shadowspawn may I ask that you stop giving this advice? It doesn’t work for users whose system has gotten into this state (see, e.g., here and a couple more posts in this forum) and it won’t bring you a step closer to figuring out what’s going on. To be specific, don’t give the advice if a user reports EISDIR with a path that ends in .npm/_cacache/content-v2/sha512/??/??. Recall that the correct path is .npm/_cacache/content-v2/sha512/??/??/restofhash if the hash is ????restofhash. The fact that accessing .npm/_cacache/content-v2/sha512/??/?? fails is not a permissions issue; this is supposed to fail since this pathname is supposed to correspond to a directory.

I would instead try to catch one of these cases and see if the user can help you track it down. First, I’d ask the user to run with BLUEBIRD_DEBUG=1, e.g.

sudo env BLUEBIRD_DEBUG=1 npm install -g n latest

and see if we’ll get a longer stack trace for the unhandled rejection.

In addition, I’d ask for the output of

sudo ls -ld /Users/cbh/.npm/_cacache/content-v2/sha512/3f/99/*

ps: if the user were willing to tar up their entire ~/.npm/_cacache folder as root things would look even more debuggable.

(Oops, I have a standard reply when I see EISDIR and .npm together. I shall be more selective.)