npmのインストールでpermissionでエラーになるとき

npm install
で以下のようなエラーになる場合の対策です。
npm ERR! code EEXIST
npm ERR! syscall rename
npm ERR! path /Users/username/.npm/_cacache/tmp/8e57c732
npm ERR! dest /Users/username/.npm/_cacache/content-v2/sha512/1f/12/36fb3bef516d75089c551e45bfd2fc203ac997bb06c57e14b43e4882692989d945407e9c0582af983868af0f40e10c6e97406cb3726e33bccab2533ec803
npm ERR! errno EEXIST
npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/postcss-import: EACCES: permission denied, rename '/Users/username/.npm/_cacache/tmp/8e57c732' -> '/Users/username/.npm/_cacache/content-v2/sha512/1f/12/36fb3bef516d75089c551e45bfd2fc203ac997bb06c57e14b43e4882692989d945407e9c0582af983868af0f40e10c6e97406cb3726e33bccab2533ec803'
npm ERR! File exists: /Users/username/.npm/_cacache/content-v2/sha512/1f/12/36fb3bef516d75089c551e45bfd2fc203ac997bb06c57e14b43e4882692989d945407e9c0582af983868af0f40e10c6e97406cb3726e33bccab2533ec803
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in: /Users/username/.npm/_logs/2024-04-09T08_01_45_337Z-debug-0.log
キャッシュを削除することで解決します。
sudo
をつけないと同様のエラーが発生します。
sudo npm cache clean --force
システム開発のご相談はお気軽に
要件定義から運用まで、お客様のビジネスに最適なシステムをご提案いたします。
まずはお気軽にご相談ください。
初回相談無料
お見積もり無料
土日対応
今月の見積もり受付、残り2社様です
お問い合わせ・ご相談