You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo预构建React Native项目TextInput报错:需有效sessionID

Expo Prebuild后iOS TextInput报错:sessionID无效+CoreGraphics NaN值问题

问题描述

采用Expo托管工作流并执行npx expo prebuild的React Native项目,在iOS端渲染TextInput时出现两类问题:

  • 报错[RemoteTextInput] -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID,导致组件状态无法更新输入值
  • 输入文本后触发CoreGraphics错误:[CoreGraphics] Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem.

项目依赖版本:

"expo": "~49.0.15",
"react": "18.2.0",
"react-native": "0.72.6",

使用的TextInput代码片段:

<TextInput
  style={[styles.input, { backgroundColor: lightGray }]}
  autoCapitalize="none"
  autoComplete="email"
  keyboardType="email-address"
  placeholder="Email"
  onChangeText={(text) => setEmail(text)}
  value={email}
/>
<TextInput
  style={[styles.input, { backgroundColor: lightGray }]}
  autoCapitalize="none"
  placeholder="Password"
  secureTextEntry={true}
  onChangeText={(text) => setPassword(text)}
  value={password}
/>

补充信息:创建全新npx create-expo-app项目,执行npx expo prebuild后运行npx expo run:ios,仍复现相同问题。

解决方法

1. 排查样式中的NaN值

CoreGraphics的NaN错误几乎都是样式参数无效导致的,重点检查styles.input:

  • 确认所有数值型样式属性(如width、height、padding、margin等)没有NaN或undefined值
  • 排查是否有计算错误(比如除以0、使用未初始化的变量参与计算)
  • 替换可能返回NaN的动态计算,改用固定数值测试

2. 调整Expo依赖版本

Expo 49.0.15与RN 0.72.6的组合存在iOS TextInput兼容性问题,尝试:

  • 升级Expo到49.x分支的最新稳定版:
    npm install expo@~49.0.21
    
  • 或降级到Expo 48.x版本,重新执行npx expo prebuild后构建

3. 清理iOS构建缓存

执行以下命令彻底清理缓存,避免旧构建文件残留问题:

# 修复Expo依赖
npx expo install --fix
# 进入iOS目录清理Pod缓存
cd ios
pod deintegrate
pod cache clean --all
rm -rf Podfile.lock
pod install
cd ..
# 重新构建iOS项目
npx expo run:ios

4. 简化TextInput属性排查

临时简化TextInput的属性,先确认基础功能是否正常:

// 简化测试代码
const [testText, setTestText] = useState('');
<TextInput
  style={{ width: 200, height: 40, borderWidth: 1 }}
  placeholder="Test Input"
  onChangeText={setTestText}
  value={testText}
/>

如果简化后正常,再逐个添加原属性,定位触发问题的具体属性。

5. 检查Xcode版本

Expo 49要求Xcode版本≥14.3,如果你的Xcode版本过低,升级到符合要求的版本后重新构建项目。

内容的提问来源于stack exchange,提问作者David Henry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 06:08:10