When I run ~$ npm install -g typescript
The following message shows:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/typescript
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/typescript'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexz/.npm/_logs/2021-12-26T10_45_08_412Z-debug.log
and i tried to check if I have successfully installed typescript, if I run npm ls typescript
it shows:
alexz@ /Users/alexz
└── [email protected]
I am confused if I have installed typescript or not, because if I do tsc -v it tells me the tsc command is not found.
How do I fix the above problem? Thanks.
CodePudding user response:
It is a permission issue. Use sudo
command, it will ask you your computer password.
sudo npm install -g typescript
CodePudding user response:
dont use sudo to install global packages ! it looks like global npm installed with wrong privlages please check which user the global npm is used by
which npm | xargs ls -ltrh
then change the node_modules dir privalges here
/usr/local/lib/node_modules/typescript'
to the same user with
chown
command