The access/permission error is a result of using sudo while installing packages using pm. Make sure you never use sudo for it.
So now, to fix the issue : The first thing you should check for when you see in this error is the directory location which is causing the permission issue. Usually it is one of the following :
/usr/local/lib/node_modules
/Users/your-username (your-username is your actual system username)
Now open your terminal and run the following command :
sudo chown -R $(whoami):staff /usr/local/lib/node_modules
and
sudo chown -R $(whoami):staff /Users/your-username
This command will change the directory owner to your user profile and then you won’t need sudo or root rights to access the folder.
有话要说