Home > Enterprise >  npm install typescript failed
npm install typescript failed

Time:12-27

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:

don't use sudo to install global packages! from now any time your going to use it your going to exec it with root privileges today your npm package is typescript yu don't know what you're going to install tomorrow

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

CodePudding user response:

It is a permission issue. Use sudo command, it will ask you your computer password.

sudo npm install -g typescript
  • Related