M1マシンでflowが起動しない問題の対応


事象

M1(apple silicon)マシンでrosettaを使って入れたnode.jsで npx flow などでflowを起動すると以下のようなエラーが出て起動に失敗する

Launching Flow server for /Users/sogasawara/progate
Spawned flow server (pid=6001)
Logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.log
Monitor logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.monitor_log
Launching Flow server for /Users/sogasawara/progate
Spawned flow server (pid=6008)
Logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.log
Monitor logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.monitor_log
Launching Flow server for /Users/sogasawara/progate
Spawned flow server (pid=6012)
Logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.log
Monitor logs will go to /private/tmp/flow/zSUserszSsogasawarazSprogate.monitor_log
Lost connection to the flow server (0 retries remaining): -Out of retries, exiting!

ログ

[2021-01-27 17:22:16.301] argv=/Users/sogasawara/progate/node_modules/flow-bi
Unhandled exception: Unix.Unix_error(Unix.EINVAL, "ftruncate", "")
Raised by primitive operation at file "hack/heap/sharedMem.ml", line 82, char
Called from file "hack/heap/sharedMem.ml", line 146, characters 5-26

環境

Mac Mini(M1), node v10.16.3 (rosetta), flow 0.90.0

解決策(workaround)

.flowconfigに以下のオプションを追加する

[options]
sharedmemory.heap_size=2147483648

なお、公式のissueに問題の対応方法が書いてあります
https://github.com/facebook/flow/issues/8538

heap_sizeはマシンのメモリによって変わるとか。

私のマシンはMac miniのメモリ16GBですが上記の値で動きましたがマシンによって調整が必要そうです