我正在尝试使用 ngrok 隧道在 iOS 设备上运行我的 Expo 应用程序,因为我目前连接到不允许我的 iOS 设备访问我的 Macbook 上的 Expo 服务的公共 wifi。
首先,我尝试了建议的命令
npx expo start --tunnel
,但它在安装@expo/ngrok
时出现错误,即使它已经在全球范围内安装了它。
CommandError: Please install @expo/ngrok@^4.1.0 and try again
% npx expo start --tunnel
Starting project at /Users/foo/expo-project
Starting Metro Bundler
✔ The package @expo/ngrok@^4.1.0 is required to use tunnels, would you like to install it globally? … yes
Installing @expo/ngrok@^4.1.0...
> npm install --global @expo/ngrok@^4.1.0
Installed @expo/ngrok@^4.1.0
CommandError: Please install @expo/ngrok@^4.1.0 and try again
接下来我尝试使用
brew
安装 ngrok 并在端口 3000 上启动它
npx expo start --tunnel
但它再次要求安装@expo/ngrok
并且安装失败并出现相同的错误。
也试过
npx expo start
,用手机扫描二维码但仍然无法连接到Expo项目,可能是因为它没有尝试通过ngrok隧道连接。
我们还能尝试什么?
安装
@expo/ngrok@^4.1.0
全局和作为对相关项目的开发依赖为我解决了这个问题。