[英]Error in installing 'nodemon' using 'npm'
我最近開始使用“npm”並使用命令安裝“nodemon”時 -
npm i -g nodemon
但它顯示錯誤!
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! dest /usr/local/lib/node_modules/.nodemon-SfftGed4
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/nodemon' -> '/usr/local/lib/node_modules/.nodemon-SfftGed4'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/nodemon' -> '/usr/local/lib/node_modules/.nodemon-SfftGed4'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/nodemon',
npm ERR! dest: '/usr/local/lib/node_modules/.nodemon-SfftGed4'
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/rishabhsingh/.npm/_logs/2023-01-28T12_41_30_475Z-debug-0.log
我嘗試使用sudo
安裝 nodemon,使用npm cache clear
清除緩存即使使用--force
也清除緩存但沒有幫助,還嘗試了顯示我的終端可能是錯誤但結果沒有任何幫助。
小心這些東西!
不要隨意運行sudo
命令。 一些在線答案會告訴您在 /usr 目錄中運行chmod
或chown
。 這不是一個好的解決方案,可能會破壞您的整個系統!
問題是 npm 試圖在您的 /usr 文件夾中安裝全局包,但您的用戶無權訪問該文件夾。 您需要做的是告訴 npm 在您有權訪問的文件夾中安裝全局包。
mkdir "${HOME}/.npm-packages"
npm config set prefix "${HOME}/.npm-packages"
.bashrc
或.zshrc
並將以下代碼添加到文件底部來完成。NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.