#はじまり
npmでのインストールができない。
npm install -g @vue/cli
以下のようなエラーが出た
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules'
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/〜〜〜〜〜〜〜/.npm/_logs/2021-11-27T03_37_32_265Z-debug.log
対策
同じような問題に遭遇した記事を発見
https://qiita.com/okohs/items/ced3c3de30af1035242d
公式ドキュメントにもエラーの対処法がある
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
どうやらさnodejsを再度インストールするのが推奨らしい
再インストールする
しっかり記事を読まずに再インストールしたらうまくいかなかった
この記事参考にしてアンインストールし、普通にインストールし直した。
https://qiita.com/nanbuwks/items/7d1baa3b06b7af169330
もう一度試す
node:internal/bootstrap/switches/does_own_process_state:126
cachedCwd = rawMethods.cwd();
^
Error: ENOENT: no such file or directory, uv_cwd
at process.wrappedCwd (node:internal/bootstrap/switches/does_own_process_state:126:28)
at process.cwd (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19)
at new Config (/usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:92:19)
at new <anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:83:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:71:30)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
errno: -2,
code: 'ENOENT',
syscall: 'uv_cwd'
}
なんだこれ...
ターミナル再起動してもう一度実行
とりあえずエラーメッセージ貼り付けてググってみたら、npmではないけれど、似たようなエラーの出てきている人がいた。ターミナル立ち上げ直したら動いたらしいのでやってみる。
https://teratail.com/questions/67522
npm notice
npm notice New patch version of npm available! 8.1.0 -> 8.1.4
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.1.4
npm notice Run npm install -g npm@8.1.4 to update!
npm notice
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/@vue
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@vue'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@vue'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/@vue'
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/matsuokahikaru/.npm/_logs/2021-11-27T03_53_56_693Z-debug.log
また似たようなエラーが。ここで、安直にインストールし直してもダメなのだと痛感し、ちゃんと調べることにした。
公式ドキュメント読んでインストールし直す
どうやらnvmを使ってnodeとnpmをインストールすると、permissionの問題は回避できるらしいので、nvmをインストールする。
ソース
https://github.com/nvm-sh/nvm#installing-and-updating
Readmeに書いてあるコマンドを実行
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm -v
command not foundが出ました。以下のコマンドを実行したら無事動きました。
source ~/.bash_profile
npmをインストールする
nvm install stable --latest-npm
npm install -g @vue/cli
いけたぁ