Global installs (sudo npm i -g) fail on Mac after 6.5 upgrade. Works fine after 6.4.1 downgrade.

help-wanted
cli
triaged
priority:medium
(Justin Grant) #1

What I Wanted to Do

Install a global package using sudo npm -g on my Mac running NPM 6.5

What Happened Instead

Every global install failed. Errors included many like this:

WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/widest-line'

And finally one like this that stopped the install:

npm WARN enoent ENOENT: no such file or directory, open '/private/tmp/npm-31930-3d7b0f16/unpack-dda66812/node_modules/run-queue/package.json'

npm ERR! path /private/tmp/npm-31930-3d7b0f16/unpack-dda66812/node_modules/run-queue/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/private/tmp/npm-31930-3d7b0f16/unpack-dda66812/node_modules/run-queue/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

Reproduction Steps

  1. Install node via downloadable Mac (Mojave 10.14.2) installer: https://nodejs.org/dist/v10.14.2/node-v10.14.2.pkg
  2. sudo npm install -g npm@6.4.1 to downgrade to working NPM
  3. sudo npm i -g serverless
  4. Works fine.
  5. sudo npm install -g npm@latest
  6. sudo npm i -g serverless
  7. FAIL!

Details

Here’s the NPM debug log shown on 6.5 when trying to re-install the serverless package (after it was successfully installed after the 6.4.1 downgrade, per the repro above).
2018-12-14T19_09_42_771Z-debug.log (292.4 KB)

I’m a new user on this forum so can’t post multiple log files, but before I successfully upgraded the serverless package (via downgrade to 6.4.1) I tried to install it earlier and it still failed, but in addition to the eventual error I also got a bunch of warnings like this:

WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/npm-3e479054/node_modules/widest-line'

Let me know if you need the logfile including these warnings and I can email it to you (or can attach here if I can get permission to do it).

BTW, here’s a support thread reporting the same problem: EISDIR: illegal operation on a directory, open

Platform Info

$ npm --versions
{ npm: '6.5.0',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.14.2',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.45',
  zlib: '1.2.11' }

$ node -p process.platform
darwin
EISDIR: illegal operation on a directory, open
update error cb() never called!
Trouble to run create-react-app
Unhandled rejection Error: EISDIR: illegal operation on a directory
EACESS error while installing locally
error cb() never called! on macOs Mojave
Solution to the EISDIR connundrum
[crash] npm ERR! cb() never called!
Error installing package
opencv4nodejs not installing in MAC OS Mojave 10.14
Unable to install packages on MacOS
Is running npm via sudo safe?
Is running npm via sudo safe?
Gatsby Won't Build Site Due to NPM error
Error while uninstalling ionic on mac
Error while creating a react-app
An error with NPM itself
Fehler bei Plugin Update
Error with npm.... error cb() never called!
NPM self-reporting error, how to solve it
NPM self reporting error while using create-react-app
error in npm when creating new ember project
Can't create react app
npm ERR! cb() error Bug
Unable to Install react Native due to npm Issue
npm leaves corrupted write-protected cache and can't auto cleanup it. leads install always failed
Unable to install redux-firebase in my react project
Unhandled Rejection Errors
Getting an error code and idk what to do
npm install error on resolving ionic 3 project error
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/tmp'
NPM install Not Working on azure pipeline
Having EACCES issues that nothing seems to fix
[crash] npm ERR! cb() never called!
(Alexander Hörl) #2

You don’t have to use sudo before npm install -g on mac actually.

Can you install other packages globally besides serverless ?

(Kat Marchán) #3

This might be a node-tar related issue, possibly. Your log doesn’t show any WARNings, though. Can you DM me one that does include this? I’m gonna /cc @isaacs too.

(Justin Grant) #4

@zkat - here’s another file with lots of WARN lines:
2018-12-14T18_55_55_453Z-debug.log (181.3 KB)

In other news, while investigating @AlexanderProd’s suggestion, I uninstalled the serverless package and then upgraded NPM and re-installed serverless it on npm 6.5. That worked! Something about uninstalling and re-installing fixed whatever problem was there. If you want me to recover the previous state to help repro the problem, I can probably pull the files out of Time Machine backups if you tell me what folders (on a Mac) are needed.

@AlexanderProd - Oh, I don’t use many global packages and serverless definitely requires sudo, so I just assumed that all global installs needed sudo. I just tried and other packages worked without sudo! Thanks for the tip.

(Matthew Riddell) #9

I gave myself access to /usr/local/lib/node_modules and then ran npm install forever -g without sudo and it was fine.

1 Like
(Kat Marchán) #10

I’m deleting any “me too” posts. If you’re not adding any new information, please use the voting feature at the top of this thread instead.

(John Gee) #13

Changing the ownership of files and then avoiding use of sudo is a possible work-around for EISDIR with global installs using sudo. Assuming this is your personal computer, and installing to default location on Mac:

sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib
sudo chown -R $(whoami) /usr/local/bin

Then try your command again without sudo. e.g.

npm install -g npm@latest

Note also, you can vote for this issue to give it more weight:

14 Likes
cb() never called! error
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/<username>/.npm/_cacache/content-v2/sha512/4c/13'
sudo npm install -g npm giving bugs
Getting an error cb() never called .
EACCES: permission denied - react-native-cli
vue create vue3.0
Error while uninstalling ionic on mac
This is an error with npm itself. Please report this error
npm 1 unhandled rejection error
npm i -g concurrently fails
npm install socket.io and socket.io-client results in an error
Global install of lerna fails with 6.9.0
This is an error with npm itself.
This is an error with npm itself (v6.9.0)
errorwheninstallingnpm
I was told to report here...
illegal operation on a directory
npm install @amplify/cli bug
npm has no permission to rename folder in WSL
Bug found with NPM
an erro when I try "npm install"
Problem while using generator-loopback with YeoMan
OSC install error: "EACCES: permission denied"
no puedo instalar ionic
npm ERR! cb() never called! macOS
Unhandled rejection Error: EACCES: permission denied
Error updating node, instructed to report it here.
npm install -g jasmine error
Npm error. First time installing
Trying to get React working
nodemon is not installed properaly in my mac Ask Question
EACCES: permission denied
Can Not Install Node Update nor Homebridge Plug ins
unable to install webpack-dev-server on mac
problem when trying to install polymer cli
Latest Mac can't install any packge globally, 6.7.0
Trying to update node
(Ole Ersoy) #15

I think I’m having the same issue on Ubuntu. I originally reported it against the Node repository here:

I’m running npm 6.7.0.

I tried downgrading all the way to 6.3.0, but it’s not helping. I still get this:

ole@mki:~/SuperflyCSS/cli$ npm --version
6.3.0
ole@mki:~/SuperflyCSS/cli$ npm i -g
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (../../../../../SuperflyCSS/cli/node_modules/fsevents):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/home/ole/.nvm/versions/node/v11.0.0/lib/node_modules/.staging/fsevents-a1705062/node_modules/abbrev' -> '/home/ole/.nvm/versions/node/v11.0.0/lib/node_modules/.staging/abbrev-0e9f4c13'

npm ERR! path /home/ole/.nvm/versions/node/v11.0.0/lib/node_modules/.staging/@superflycss/cli-5549c074/node_modules/@babel/code-frame
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/home/ole/.nvm/versions/node/v11.0.0/lib/node_modules/.staging/@superflycss/cli-5549c074/node_modules/@babel/code-frame' -> '/home/ole/.nvm/versions/node/v11.0.0/lib/node_modules/.staging/@babel/code-frame-78217d7a'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ole/.npm/_logs/2019-02-07T18_06_44_825Z-debug.log
ole@mki:~/SuperflyCSS/cli$ 

Also tried upgrading to latest version of node. Same result.

(Ole Ersoy) #17

I solved it on Ubuntu by upgrading node to v11.9.0 using NVM and using npm 6.7.0.

(Justin Grant) #18

BTW, this solution from @shadowspawn worked perfectly on my Mac w/Mojave to enable global installs of NPM and other packages without requiring sudo. It even works for the serverless package which kicked off this thread. Thanks John!

2 Likes
(Jim) #19

I’m on macOS Mojave Version 10.14.2
Solution from @shadowspawn doesn’t work for me and also I get the same error trying to downgrade it as well with sudo npm install -g npm@6.4.1
Please I need a fix

(John Gee) #20

@asdad2

  1. The instructions I gave assume you are installing global modules to /usr/local/. Is that the case for you?
$ npm -g prefix
/usr/local
  1. What error are you getting? (What path is mentioned?)
(Umberto Benelli) #22

Hi @shadowspawn! I have the same issue of @asdad2. I’ve just launched npm -g prefix and the result it’s exactly “/usr/local”.
If I try to downgrade with “sudo npm install -g npm@6.4.1”, I have a long list of error on many files. Below some of this error:

npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/bin/node-gyp-bin’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/changelogs’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/doc/cli’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/doc/files’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/doc/misc’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/doc/spec’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/html/doc/cli’
npm WARN tar EISDIR: illegal operation on a directory, open ‘/tmp/npm-19865-334adb21/unpack-3b041077/html/doc/files’

Do you have any idea?
Thanks!!

(John Gee) #23

@umbeb

I am not sure about error in tmp location. You could try the downgrade command with an explicit tmp directory:

mkdir /tmp/delete_me
sudo npm_config_tmp=/tmp/delete_me npm install -g npm@6.4.1
sudo rm -rf /tmp/delete_me
(Tarnalcock) #24

Can confirm. This worked for me. Using WebStorm console, macOS Mojave.

(Tarnalcock) #25

My issues were also with /tmp but after using the chown commands you specified it all worked. I assume (have not investigated further) that it may be something to do with copying from /tmp to ~/.npm or such.

(Ttt163) #26

升级npm,导致node和npm不匹配,你应该重新去官网下载安装node再升级npm

(Matthias Ott) #27

Some for me. This solution worked like charm – and saved my evening. :) Thanks a lot, John!

2 Likes
(John Gee) #28

I am linking to this topic a lot, so I’ll add a general note too.

It is good practice to avoid using sudo with npm, but this does require a little extra work. Your three main options are:

  1. change the ownership of the global install location
  2. change the location of the global install location to somewhere you own, by changing where you install node and npm (node version managers typically do this)
  3. change the location of the global install location to somewhere you own, by changing npm configuration
1 Like
Do I really need to backup my computer to fix the EACES error?
(Thirumaleshwar Kunamalla) #29

Thanks John.
Your solution worked well.

1 Like