Expo - CommandError ngrok tunnel took too long to connect.

記錄在 Expo 使用 tunnel 分享 iOS app 時遇上的問題 `CommandError: ngrok tunnel took too long to connect.`

想分享以 Expo 製作的 iOS app 給不在相同 WiFi 環境下的人以 Expo Go 試用,若果用 EAS, 那需要一個付費的 Apple 開發者帳號。

若果是經 Tunnel 那就不用。這裡記錄遇到的一個問題。

問題

使用指令 npx expo start -c --tunnel 時,會出現錯誤 CommandError: ngrok tunnel took too long to connect.

測試

網上不少討論,以下是一些解決方法:

  1. npx expo start --tunnel 時額外加上 --reset-cache
  2. 重裝 npm install -g @expo/ngrok
  3. 關掉防火牆
  4. 額外安裝 brew install ngrok
  5. 額外安裝開發依賴 npm install -D @expo/ngrok

但以上方法都無法解決問題。

解決方法

我不肯定是不是受到 fnm 影響了 (可查閱 npm config get prefix)。

以下是我認為應該有幫助的事:

  1. 去 ngrok.com 註冊帳號
  2. 根據指示安裝並加入 authtoken (ngrok config add-authtoken xxxxxxxxxxx)
  3. ngrok http 8081 對應 Expo 的 Port
  4. npx expo start,無需加上 --tunnel
  5. 分享你的開發域名,末端加上 /_expo/loading (比如 https://aaa-bbb-ccc.ngrok-free.dev/_expo/loading)
  6. 選擇以 Expo Go 打開

這樣子便成功了。

References

https://docs.expo.dev/more/expo-cli/#tunneling

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy