現在エンジニアを目指して学習中です。
npmでのパッケージインストールにて発生したエラーについて
全く同じパターンでの日本語の事例がうまく見つけられなかったので、メモしておきます。
前提
npmでパッケージをインストールしようとしたら
npm install -g browserify
こんなエラーが発生しました。タイムアウトした、、?
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/glob reason: Invalid response body while trying to fetch https://registry.npmjs.org/glob: Socket timeout
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/hogehoge/.npm/_logs/2022-10-29T06_22_42_874Z-debug-0.log
解決までの動き
エラー箇所の特定
色々調べましたが、全く同じパターンのクリティカルな解決策は見つけられず、、
npmが正常に作動するか調べるコマンドnpm doctor
の存在を知り、実行
npm ERR! checkFilesPermission Missing permissions on /usr/local/bin/.keepme (expect: executable)
Check Value Recommendation/Notes
npm ping ok
npm -v ok current: v8.19.2, latest: v8.19.2
node -v not ok Use node v18.12.0 (current: v18.11.0)
npm config get registry ok using default registry (https://registry.npmjs.org/)
which git ok /usr/local/bin/git
Perms check on cached files ok
Perms check on local node_modules ok
Perms check on global node_modules ok
Perms check on local bin folder ok
Perms check on global bin folder not ok Check the permissions of files in /usr/local/bin
Verify cache contents ok verified 155 tarballs
npm ERR! Some problems found. See above for recommendations.
2か所でnot OKが出ているようですね。
なので、ひとまずこれを解消します。
nodeのバージョンアップデート
node -v
v18.11.0
確かに、現在はv18.11.0となっているようです。
これをv18.12.0にしたいので、アップデート。
Macの方はこちらを参照。インストールしただけでOKでした。
https://nodejs.org/ja/download/package-manager/#macos
node -v
v18.12.0
OK!!
Perms check on global bin folder
権限が正しく設定されていないらしい。
正直よくわからないままに、調べたまま以下を実行したら解決した。
※同じくわかっていない方はこの後紹介するコマンドを試した後の方が良いかと思います。
rm -rf /usr/local/bin/.keepme
rm …削除する
rm -rf …問答無用で削除
…ん??つまり、.keepmeファイルを削除したっぽい。
あれ、これ大丈夫か、、、、、、、、、、
まあダメだったとして、ローカル環境で誰かに害を与えることはないと思うので
今後の良い糧として捉えましょう。。
rm -rfは無知なまま実行するのは良くないですね。
以下も紹介されていたので、まずはこちらを試してみた方が良さそうです。
chmod +x /usr/local/bin/.keepme
chmod +x
でx権限(書き込み可)を付与しています。
結果
npm doctor
を再度実行
Check Value Recommendation/Notes
npm ping ok
npm -v ok current: v8.19.2, latest: v8.19.2
node -v ok current: v18.12.0, recommended: v18.12.0
npm config get registry ok using default registry (https://registry.npmjs.org/)
which git ok /usr/local/bin/git
Perms check on cached files ok
Perms check on local node_modules ok
Perms check on global node_modules ok
Perms check on local bin folder ok
Perms check on global bin folder ok
Verify cache contents ok verified 155 tarballs
OK!!
インストールを再度実行します。
npm install -g browserify
無事に完了しました!
参考
解決までの流れ
permission-errorsの解決
chmodコマンド