當我運行 ~$ npm install -g typescript
以下訊息顯示:
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
我嘗試檢查是否已成功安裝打字稿,如果我運行npm ls typescript
它會顯示:
alexz@ /Users/alexz
└── typescript@4.5.4
如果我安裝了 typescript,我很困惑,因為如果我執行 tsc -v 它會告訴我找不到 tsc 命令。
我如何解決上述問題?謝謝。
uj5u.com熱心網友回復:
這是一個許可問題。使用sudo命令,它會詢問您的計算機密碼。
sudo npm install -g typescript
uj5u.com熱心網友回復:
不要使用 sudo 安裝全域包!從現在開始,無論何時您要使用它,您今天都要以 root 權限執行它,您的 npm 包是打字稿,您不知道明天要安裝什么
看起來全域 npm 安裝了錯誤的權限,請檢查全域 npm 是由哪個用戶使用的
which npm | xargs ls -ltrh
然后在這里更改 node_modules dir privalges
/usr/local/lib/node_modules/typescript'
使用chown命令發送給同一用戶
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/395466.html
下一篇:React依賴樹問題
