Expo iOS开发构建启动报错:Cannot read property 'getIosIdForVendorAsync' of undefined
解决方案建议
问题根源
getIosIdForVendorAsync 是 expo-device 库专属的iOS设备API,出现该错误的核心原因是:项目未安装expo-device依赖,或者导入/调用方式有误,导致运行时无法找到该方法。
具体解决步骤
1. 安装expo-device依赖
在项目根目录执行命令,确保依赖版本与Expo SDK兼容:
npx expo install expo-device
2. 修正代码中的导入与调用逻辑
确保代码中正确导入库,并在iOS环境下安全调用:
import * as Device from 'expo-device'; import { Platform } from 'react-native'; // 仅在iOS平台调用该API if (Platform.OS === 'ios') { try { const vendorId = await Device.getIosIdForVendorAsync(); // 后续业务逻辑处理 } catch (error) { console.error('获取设备Vendor ID失败:', error); } }
注意:检查方法名拼写,确保是getIosIdForVendorAsync(大小写敏感)
3. 重新构建开发包
依赖安装完成后,重新执行构建命令,确保native模块被正确打包进iOS开发客户端:
eas build --profile development --platform ios
4. 额外排查点
- 检查
package.json中expo与expo-device的版本兼容性,避免版本不匹配导致的模块失效 - 确认
eas.json的development配置中未添加排除expo-device的自定义native配置
内容的提问来源于stack exchange,提问作者Marc Aparisi
相关产品推荐
相关产品推荐

