WSL上に環境構築したnpmでパッケージ管理しているプロジェクトで、ライブラリをuninstallするときに、以下のエラーが出た。
$ npm install {ライブラリ名}
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /home/~/project/frontend/node_modules/ansi-colors
npm ERR! dest /home/~/project/frontend/node_modules/.ansi-colors-fx0IfCCD
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/home/~/project/frontend/node_modules/ansi-colors' -> '/home/~/project/frontend/node_modules/.ansi-colors-fx0IfCCD'
npm ERR! [Error: EACCES: permission denied, rename '/home/~/project/frontend/node_modules/ansi-colors' -> '/home/~/project/frontend/node_modules/.ansi-colors-fx0IfCCD'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/home/~/project/frontend/node_modules/ansi-colors',
npm ERR! dest: '/home/~/project/frontend/node_modules/.ansi-colors-fx0IfCCD'
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! /home/~/.npm/_logs/2023-04-15T23_20_51_237Z-debug-0.log
ワークアラウンドは以下の通り
①エディタのウィンドウを閉じる(その他WSLのターミナルを開いているウィンドウは全部閉じる)
②WSLのWindowsアプリを管理者権限で実行
③プロジェクトのフォルダに移動して、npm uninstallを実行