如何解决Expo中‘ngrok tunnel took too long to connect’报错问题?
解决Expo
ngrok tunnel took too long to connect 错误的两种方案 一、增加ngrok超时时间
Expo CLI默认的ngrok超时时间为10秒(10000ms),无需寻找本地配置文件,直接通过环境变量即可修改:
- 类Unix系统(Mac/Linux),在启动命令前添加超时参数(示例设置为30秒):
EXPO_TUNNEL_TIMEOUT=30000 expo start --tunnel - Windows PowerShell环境,先设置变量再启动:
$env:EXPO_TUNNEL_TIMEOUT=30000; expo start --tunnel
同时建议更新Expo CLI到最新版本,新版本可能优化了隧道连接的超时判断逻辑:
npm install -g expo-cli
二、手动运行ngrok复现Expo隧道
手动启动ngrok并关联Expo的步骤如下:
- 单独启动Metro Bundler(不启用Expo自带隧道):
expo start --no-tunnel - 打开新终端,运行ngrok转发Metro默认端口(8081):
运行后会输出类似ngrok http 8081https://xxxx-xx-xx-xx-xx.ngrok.io的HTTPS地址,复制该地址。 - 回到Expo终端,停止当前进程,用以下命令指定手动隧道启动:
也可通过环境变量传递隧道地址:expo start --tunnel --ngrok-url https://xxxx-xx-xx-xx-xx.ngrok.ioEXPO_TUNNEL_URL=https://xxxx-xx-xx-xx-xx.ngrok.io expo start --tunnel
额外排查建议
- 若手动运行ngrok仍缓慢,可指定就近的区域节点(示例为亚太区):
ngrok http 8081 --region ap - 检查本地防火墙、代理是否拦截ngrok出站请求,可暂时关闭测试。
- 确认Expo服务器运行状态正常。
内容的提问来源于stack exchange,提问作者Keith Stein
相关产品推荐
相关产品推荐

