🚒

Mac で突然 node-gyp のエラーが出た時の対処法

2020/10/01に公開

TL;DR

  1. pkgutil --packages | grep CL して出力が出ないことを確認
  2. yarn cache clean
  3. sudo rm -rf $(xcode-select -print-path)
  4. xcode-select --install
  5. 4 が "xcode このソフトウェアは、現在ソフトウェア・アップデート・サーバから入手できないため、インストールできません。" などと言われて失敗する時はApple公式サイトから Xcode Command Line Tools をダウンロードしてインストールする
  6. pkgutil --packages | grep CL して出力が出ることを確認

突然 node-gyp のエラーが出た

.NET Core のチュートリアル Authentication and authorization for SPAs
を実施するにあたって dotnet run で yarn が走ったときに以下のようなエラーが出た

EXEC : gyp ERR! stack error : `gyp` failed with exit code: 1 [angularIndividualTest.csproj]
EXEC : gyp ERR! stack error : `gyp` failed with exit code: 1 [angularIndividualTest.csproj]
EXEC : gyp ERR! stack error : `gyp` failed with exit code: 1 [angularIndividualTest.csproj]
EXEC : gyp ERR! stack error : `gyp` failed with exit code: 1 [angularIndividualTest.csproj]
EXEC : Build failed with error code: 1 [angularIndividualTest.csproj]
angularIndividualTest.csproj(43,5): error MSB3073: コマンド "npm install" はコード -1 で終了しました。

ビルドに失敗しました。ビルド エラーを修正して、もう一度実行してください。

調べたところ、 node-gyp でエラーが出ているらしく
Xcode Command Line Tools を再インストールすればいいらしいのだが
xcode-select --install がコケるので別の方法が必要だった

参考

Discussion