Mac - install angular using CLI :- Unhandled rejection Error: EISDIR: illegal operation on a directory

Hi Team,

I was trying to install angular on my mac. I run following command on my CLI
sudo npm install -g @angular/cli

And it returns following error message :-
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/apple/.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

As above error message is saying it is an error with npm itself, so I am reporting it here.

(Reports to #bugs should use the template which includes extra information like the npm version you are running and platform you are on. Reports to #support are more freeform and I have moved your issue there.)

Welcome@Priyassk! Can you attach the log file?

Sure.

Please find attachment below

2019-06-01T10_17_48_546Z-debug.log (517 Bytes)

There are some issues with global installs using sudo leaving behind files or folders with wrong permissions, and some people have reported issues with tmp folder too. The canonical thread is: Global installs (sudo npm i -g) fail on Mac after 6.5 upgrade. Works fine after 6.4.1 downgrade.

I’m not sure where your situation fits in!

Given you have a problem in the cache, a simple thing to try is clearing the cache, then trying your install again:

npm cache clear --force
sudo npm install -g @angular/cli

Before you follow @shadowspawn advice, would you mind running

sudo env BLUEBIRD_DEBUG=1 npm install -g @angular/cli

and sharing the output?

1 Like

I do not have a certain work-around, and @godmar is looking for deeper understanding of this failure while you can still reproduce it. Please try his request before trying to fix the problem. :-)

Hi @godmar,

Thanks for concern.

After running that command, output is as following:
errors.log (38.0 KB)

And please find attachment for error log.

2019-06-03T06_16_38_840Z-debug.log (1.0 KB)

1 Like

@Priyassk thank you. The stack trace is extremely helpful.

The EISDIR error appears to occur inside chownr when cacache tries to fix the ownership of the directory it just created (not when it’s trying to read from the cache). In other words, the error occurs because npm is run under sudo (and it tries to respect the invoking user’s permissions, taking a special path only taken under sudo.)

I don’t immediately see a reason for this error, but now the search might shift away from npm/cacache proper to chownr (and possibly platform-specifics of node/libuv). It appears that npm/cacache acts the way it should.

As for possible work-arounds, I don’t think this issue can be fixed by resetting your permissions. Rather, you’ll have to read up on a way to run npm without ever using sudo (usually by resetting permissions once - or wiping your ~/.npm via sudo, then setting a different prefix, using a node version manager, etc. See here for a start.
It is a bit unfortunate IMO that the node/npm maintainers do not support the default installations of node on 2 widely used architectures (Linux + MacOS) properly.)

I left an issue describing the issue in the chownr bug tracker. Should my interpretation be correct, however, this would be a MacOS-specific issue with node.js itself.

It’s possible this has been known since 2014 but fell through the cracks.

For any Mac users encountering this, upgrade to node v10. Then, things still won’t work perfectly due to issues like pacote 174 but you shouldn’t be seeing the ‘EISDIR’ error anymore when using sudo npm .... -g

Hi.
I’m a mac user too, and I’m running version 9.11.1 of Node.js.
After doing 1000 traps to get installed the 8.0.3 version of @angular/CLI, I got this surprise, a message from my Terminal:

You are running version v9.11.1 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.

So, as @godmar said, upgrade to node v10 ;o)