You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
One of my pet peeves with npm for as far as I remember has been that when following the provided installation instructions for Linux systems (specifically installing the NodeSource provided packages in /usr) you invariably end up with a corrupted npm cache as soon as you follow the instructions to update npm that are printed as part of its update check. In fact, anytime you run npm with sudo npm install -g ... your cache is toast, meaning that it contains files owned by root.root that make it impossible to use npm in the intended way by the user who issued the npm install -g command.
I did some sleuthing and added a couple of debugging statements and my impression is that npm doesn't intend to behave that way. It appears that there is logic in place to ensure that files written while running under sudo are chown'd back to the user who invoked the sudo command as recognized by $SUDO_UID.
However, the call to cacache.put here ignores any opts.uid and opts.gid passed to it, resulting in cacache not fixing up the owner for any directories it creates. After applying the following patch:
the issue disappears, more specifically, there are no more root.root owned files in ${HOME}/.npm/_cacache after running sudo npm install -g. (Caveat: only tested with sudo npm install -g create-react-app; no claims that this fixes all known issues related to sudo and npm.)
One of my pet peeves with npm for as far as I remember has been that when following the provided installation instructions for Linux systems (specifically installing the NodeSource provided packages in
/usr
) you invariably end up with a corrupted npm cache as soon as you follow the instructions to update npm that are printed as part of its update check. In fact, anytime you run npm withsudo npm install -g ...
your cache is toast, meaning that it contains files owned byroot.root
that make it impossible to usenpm
in the intended way by the user who issued thenpm install -g
command.I did some sleuthing and added a couple of debugging statements and my impression is that npm doesn't intend to behave that way. It appears that there is logic in place to ensure that files written while running under sudo are chown'd back to the user who invoked the sudo command as recognized by
$SUDO_UID
.However, the call to cacache.put here ignores any
opts.uid
andopts.gid
passed to it, resulting incacache
not fixing up the owner for any directories it creates. After applying the following patch:the issue disappears, more specifically, there are no more
root.root
owned files in${HOME}/.npm/_cacache
after runningsudo npm install -g
. (Caveat: only tested withsudo npm install -g create-react-app
; no claims that this fixes all known issues related to sudo and npm.)This is with npm:
on node 11.15.0. My apologies if this is already addressed.
The text was updated successfully, but these errors were encountered: