npm: Unhandled rejection Error: EISDIR: illegal op

2019-07-10 04:27发布

On my Mac, I just updated my working npm version from 5.6 to 6.9 thusly:

sudo npm i -g npm

Then I tried to install cordova like this:

sudo npm install -g cordova

And get

Unhandled rejection Error: EISDIR: illegal operation on a directory, 
open '/Users/me/.npm/_cacache/content-v2/sha512/04/89'
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/me/.npm/_logs/2019-04-02T11_50_57_678Z-debug.log

I tried to downgrade thusly:

sudo npm install -g npm@6.4.1

but this fails with hundreds of lines like this:

npm WARN tar EISDIR: illegal operation on a directory, open '/tmp/npm-30934-a3ac319a/unpack-28da209e/bin/node-gyp-bin'
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/content-v2/sha512/99/72'

I also tried making sure the ownership was correct:

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

There are lots of posts of various EISDIR (error is a directory) problems for other directories (such as /usr/lib/modules), but no solutions seem to work.

Also, the npmrc file does not seem to exist. If I do:

npm config ls -l

globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/me/.npmrc"

but neither file exists.

Note, I dont have homebrew, and didnt install it that way (I usually do manual installs).

I also tried this:

sudo npm cache clean -f

This did not help.

What else can I try? should I try deleting the ~/.npm dir?

Looking for a way to uninstall node, I found many old posts with long and sometimes conflicting lists of files to remove. Not sure if this will make it worse.

Any suggestions?

标签: npm
3条回答
女痞
2楼-- · 2019-07-10 04:59

I think I have found a solution. I did the following:

  1. installed node from the Mac pkg installer from https://nodejs.org/en/ This downgraded npm to 6.4.1 which is the version before EISDIR problems start apparently.
  2. chmod -R 777 ~/.npm/_cacache // yes, this is not good
  3. chown -R me ~/.npm/_cacache

After this, I could install cordova using "sudo npm install -g cordova" without errors.

查看更多
Root(大扎)
3楼-- · 2019-07-10 05:11

Changing the ownership of files and then avoiding the use of sudo is a possible workaround for EISDIR with global installs using sudo. I suppose you have installed to default location folder:

sudo chown -R <user> ~/.npm

sudo chown -R <user> /usr/local/lib

sudo chown -R <user> /usr/local/bin

After this sequence, it worked to me.

查看更多
Lonely孤独者°
4楼-- · 2019-07-10 05:18

I had the same problem when I upgraded to npm 6.9.0. You have to upgrade node to the last version:

brew reinstall node

At this time I have installed the latest available version for Mac OS Mojave (node: v11.14.0 and npm 6.9.0).

After node upgrade, I was able to install packages globally again.

查看更多
登录 后发表回答