3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Homebrew のインストール先を変えた環境でwatchman 実行時にエラーになったら対応すること

Posted at

はじめに

プロジェクトのパッケージ管理の都合上、Homebrew のインストール先をデフォルトから変更しなければならない場合があります。

ほとんどのライブラリについては、brew installをする際に必要なパスや環境変数を変更してくれるのでインストール先を変更しても問題はないのですが、Watchmanは実行時にエラーが出てしまうことがあります。

本記事では僕が詰まった時にエラーを解決した方法についてまとめます。
自分はそこそこな時間解決までにかかったので、同じような原因で詰まってしまう方の助けになれば幸いです。

発生したエラー

Watchmanを内部的に利用するライブラリ(自分の場合はserverless-appsync-pluginでした)の開発環境の起動時に下記のようなエラーが発生しました。

Error: watchman --no-pretty get-sockname returned with exit code=1, 
signal=null, stderr= 2021-06-29T11:41:08,049: [] 
while computing sockname: failed to create /usr/local/var/run/watchman/some-user-state:
 No such file or directory
  
      at ChildProcess.<anonymous> (/Users/some-user/some-project/node_modules/fb-watchman/index.js:198:18)
      at ChildProcess.emit (events.js:314:20)
      at ChildProcess.EventEmitter.emit (domain.js:483:12)
      at maybeClose (internal/child_process.js:1022:16)
      at Socket.<anonymous> (internal/child_process.js:444:11)
      at Socket.emit (events.js:314:20)
      at Socket.EventEmitter.emit (domain.js:483:12)
      at Pipe.<anonymous> (net.js:675:12)

解決方法

ディレクトリが作成できないとエラーが出ているので、下記のコマンドでディレクトリを作成しました。

# 必要なディレクトリを作成する
sudo mkdir -p /usr/local/var/run/watchman/some-user-state

# そのままだとホスト権限がないと作成したディレクトリにアクセスできないので、権限を渡す
sudo chown -R some-user /usr/local/var/run/watchman

logファイルだけ/usr/local以下に作成されてしまい、少し気持ち悪いのですが実行時のエラーはこちらの方法で解決できました。

原因

公式ページにも記載のあるように Watchman は実行時のログを<PREFIX>/var/run/watchman/<USER>-state/logのディレクトリに保存します。

また、この <PREFIX>の部分はデフォルトでは/usr/localに設定されています。

Watchman places the logs in a file named /log, which will typically be a location like /var/run/watchman/-state/log. If you’re running a homebrew build of watchman, is usually /usr/local.

Homebrewのデフォルトのインストール先も/usr/localなので、デフォルトでインストールした場合は問題になりませんが、Homebrew のインストール先を変更していた場合は、WatchmanのバイナリはHomebrewで管理されたフォルダにありますが、logはroot権限が必要な/usr/local以下に作成されるため、インストール時に必要なディレクトリが作成されず実行時に必要なディレクトリがないとエラーになります。

WatchmanをHomebrewでインストールする際には、下記のようなコードでlogの保存先のディレクトリが作成されています。

watchman.rb
  def post_install
    (var/"run/watchman").mkpath
    chmod 042777, var/"run/watchman"
  end

参考:
HomebrewのFormula(Watchman)

その他Watchmanについて調べたことこと

1. PREFIXという環境変数を設定してみる

watchman/blob/master/autogen.shのコードをみたところPREFIXという環境変数でなんとか変更できないかと思ったのですが、設定して実行 / 再インストールを試みてもうまく動作しませんでした。

参考: watchman/blob/master/autogen.sh

2. --enable-statedir オプションで実行する

Watchmanの公式ページでは--enable-statedirオプションでSTATEDIRを変更できるよとあったのですが、ライブラリ経由でWatchmanを呼び出しており、ライブラリ側ではこちらのオプションを設定できそうになかったので実現できませんでした。

参考: Wachman > Command Line > quick-note-on-default-locations

参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?