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

运行克隆的React Native项目遇报错,寻求排查解决方法

解决方案

第一步:修复Animated.Text.propTypes.style错误

这个错误源于React Native 0.63+版本移除了核心库内置的propTypes,或是项目代码/依赖库使用了已废弃的Animated.Text.propTypes API,具体修复方式:

  • 若为自定义代码问题:
    1. 先安装prop-types库:
      npm install prop-types --save
      # 或 yarn add prop-types
      
    2. 替换原有错误代码:
      原错误写法:
      import { Animated } from 'react-native';
      Animated.Text.propTypes = {
        style: Animated.Text.propTypes.style
      };
      
      改为标准写法:
      import { Animated } from 'react-native';
      import PropTypes from 'prop-types';
      Animated.Text.propTypes = {
        style: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
      };
      
  • 若为第三方依赖问题:
    查看报错依赖包的版本,升级至兼容当前React Native版本的版本,或使用patch-package给依赖包打补丁修正废弃API的调用。

第二步:修复App未注册问题

该问题大概率是第一个错误导致组件加载失败,进而使AppRegistry.registerComponent未执行,也可能是Metro服务异常,处理方式:

  • 重启并重置Metro服务:
    1. 停止当前Metro进程(按Ctrl+C)
    2. 清除缓存并重启:
      npx react-native start --reset-cache
      # 或 yarn react-native start --reset-cache
      
    3. 重新启动项目:
      npx react-native run-android # 对应Android模拟器
      # 或 npx react-native run-ios # 对应iOS模拟器
      
  • 检查项目入口文件:
    确认index.js(或index.tsx)末尾存在正确的注册代码,且app.json中的name字段为farmsell:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    

第三步:兜底排查步骤

  • 重装依赖:
    删除node_modules和锁文件,重新安装确保依赖完整:
    rm -rf node_modules package-lock.json
    npm install
    # 或 rm -rf node_modules yarn.lock && yarn install
    
  • 核对版本兼容性:
    确认本地React Native版本与克隆项目要求的版本一致,若不一致,升级/降级至对应版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 20:22:42