rlcrews
rlcrews

Reputation: 3562

npm permission errors on folder access to node_modules

I've been trying to get npm configured to where I don't need to run npm using sudo however with everything I try every time I run an npm command I get the following error

npm WARN checkPermissions Missing write access to /Users/<MYUSERNAME>/.npm-global/lib/node_modules

This isn't the full error just edited for brevity.

Here's what I've tried so far: Installed NVM uninstalled then reinstalled node

Tried changing the permissions on the hidden folder

chmod 755 /Users/<MYUSERNAME>/.npm-global/lib/node_modules

Followed the instructions from npm on how to change the global path https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory

And finally tried to change ownership of the directory using CHOWN and still nothing. Any advice on what I am doing wrong. I've been pouring through Git issues reading what people are doing and still no luck.

Thanks in advance,

Upvotes: 2

Views: 5371

Answers (1)

rlcrews
rlcrews

Reputation: 3562

For those interested it looks like executing

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

from command line/terminal resolved the issue. I think previously I had a syntax error in what I tried. I had to run this from command line then shutdown and restart terminal. Once I restarted terminal I was able to install packages without using sudo and no errors.

I credit this stack link to addressing this issue: npm throws error without sudo

Note: for clarification for those that don't know (whoami) returns the username of who you are currently logged into your osx/terminal. This does not apply to windows or powershell

If anyone has any other approaches let me know

Upvotes: 3

Related Questions