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

升级依赖后React Native Elements报JSX组件类型错误求助

解决React Native Elements组件JSX类型错误的方案

针对升级依赖后出现的'TextInput' cannot be used as a JSX component. Its type 'typeof TextInput' is not a valid JSX element type.ts(2786)错误,可尝试以下方案:

1. 校验依赖版本兼容性

react-native-elements 3.4.3与React Native 0.72.3可能存在适配问题:

  • 查看react-native-elements版本兼容说明,升级或降级到与RN 0.72.x明确匹配的版本,比如尝试升级到3.x系列最新稳定版,或降级到标注支持RN 0.72的版本。

2. 修复TypeScript类型依赖不匹配

  • 升级@types/react到与react本体一致的版本(当前react为18.2.0):
    npm install @types/react@18.2.0 --save-dev
    
  • 升级@types/react-native到RN 0.72.x对应的最新类型版本:
    npm install @types/react-native@^0.72.10 --save-dev
    

3. 调整tsconfig.json配置

当前配置的include范围过窄,导致项目文件类型检查不完整,修改如下:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "jsx": "react-native",
    "module": "es6",
    "target": "es6",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "typeRoots": ["./src/types"],
    "esModuleInterop": true // 添加此项解决模块交互类型问题
  },
  "include": [
    "./*.d.ts",
    "src/**/*" // 包含src目录下所有文件
  ]
}

4. 清除缓存并重新构建

  • 删除项目根目录的.tsbuildinfo文件(若存在),清除TypeScript缓存
  • 执行类型检查排查细节:
    npx tsc --noEmit
    
  • 清除Metro缓存并重启项目:
    npx expo start --clear
    

5. 排查重复依赖

检查是否存在多版本的react或react-native导致类型冲突:

npm ls react
npm ls react-native

若发现重复版本,执行npm dedupe合并依赖,或手动卸载多余版本。

6. 验证导入方式

确保组件导入路径正确,直接从react-native-elements导入:

import { TextInput } from 'react-native-elements';

临时替换为React Native原生TextInput,若报错消失则问题锁定在react-native-elements的类型定义或版本适配。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 03:00:19