Mac端运行npx expo start出现错误码72的排查求助
问题描述
首次在Mac上按照Expo官方文档搭建React Native开发的Expo环境,使用VS Code创建安卓应用时,执行npx expo start出现报错。报错信息如下:
C02F1BTNMD6N:React-test-app cbattle$ npx expo start Starting project at /Users/cbattle/Dev/ReactNative/React-test-app Starting Metro Bundler Unable to run simctl: Error: xcrun simctl help exited with non-zero code: 72 TypeError: fetch failed TypeError: fetch failed at node:internal/deps/undici/undici:13502:13 at processTicksAndRejections (node:internal/process/task_queues:105:5) at fetchWithCredentials (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/api/rest/client.ts:92:24) at cachedFetch (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/api/rest/cache/wrapFetchWithCache.ts:26:24) at getNativeModuleVersionsAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/api/getNativeModuleVersions.ts:39:20) at getVersionedNativeModulesAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/start/doctor/dependencies/bundledNativeModules.ts:33:14) at getCombinedKnownVersionsAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/start/doctor/dependencies/getVersionedPackages.ts:63:7) at getVersionedDependenciesAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/start/doctor/dependencies/validateDependenciesVersions.ts:97:33) at validateDependenciesVersionsAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/start/doctor/dependencies/validateDependenciesVersions.ts:46:25) at startAsync (/Users/cbattle/Dev/ReactNative/React-test-app/node_modules/@expo/cli/src/start/startAsync.ts:109:5)
已知情况:
- 此前通过Homebrew安装过node/npm/npx,可能存在版本冲突
- 未安装Xcode
- 处于ZScaler企业代理环境中
请问该如何排查此错误?
排查方案
1. 解决代理导致的fetch failed错误
ZScaler这类企业代理会拦截Expo CLI的网络请求,导致无法获取原生模块版本信息:
- 在终端配置代理环境变量(替换为你的代理地址和端口):
export HTTP_PROXY=http://你的代理地址:端口 export HTTPS_PROXY=http://你的代理地址:端口 export NO_PROXY=localhost,127.0.0.1,::1 - 若代理需要认证,在地址中加入用户名和密码:
export HTTPS_PROXY=http://用户名:密码@你的代理地址:端口 - 验证代理是否生效:执行
curl https://api.expo.dev,能正常返回内容则配置成功。
2. 处理xcrun simctl错误
即便只开发安卓应用,Expo CLI默认会检查iOS模拟器环境,未安装Xcode会触发该错误:
- 安装Xcode命令行工具:终端执行
xcode-select --install,按提示完成安装 - 验证安装:执行
xcrun simctl help,不再返回错误码72则问题解决 - 若确实不需要iOS环境,可通过启动参数跳过检查:
npx expo start --android
3. 排查Node.js版本冲突
Homebrew安装的Node可能与系统默认版本冲突:
- 查看当前Node版本:
node -v,确认是否符合Expo要求(推荐LTS版本如18.x或20.x) - 使用nvm统一管理Node版本:
- 安装nvm后,执行
nvm install 20安装LTS版本 - 设置默认版本:
nvm alias default 20
- 安装nvm后,执行
- 清理缓存并重装依赖:
npm cache clean --force rm -rf node_modules package-lock.json npm install
4. 其他补充步骤
- 升级Expo CLI到最新版本:
npm install -g expo-cli - 执行Expo Doctor检查环境:
npx expo doctor,根据提示修复问题 - 重启终端和VS Code,确保环境变量生效
内容的提问来源于stack exchange,提问作者Clark Battle
相关产品推荐
相关产品推荐

