npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

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!

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: ‘’,
zlib: ‘1.2.11’ }

$ node -p process.platform

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.)