簡體   English   中英

使用“npm”安裝“nodemon”時出錯

[英]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 目錄中運行chmodchown 不是一個好的解決方案,可能會破壞您的整個系統!

問題是 npm 試圖在您的 /usr 文件夾中安裝全局包,但您的用戶無權訪問該文件夾。 您需要做的是告訴 npm 在您有權訪問的文件夾中安裝全局包。

  1. 為全局 npm 包創建一個目錄:

mkdir "${HOME}/.npm-packages"

  1. 告訴 npm 在哪里存放全局安裝的包L

npm config set prefix "${HOME}/.npm-packages"

  1. 確保 npm 將通過將其添加到系統的 PATH 變量中找到該位置。 這可以通過在您的主目錄中編輯.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"
  1. 關閉並重新打開您的終端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM