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

react-native-step-indicator在react-native v0.52.0中出现React.PropTypes.func未定义错误求助

解决undefined is not an object (evaluating 'React.PropTypes.func')错误

这个问题的根源很明确:你使用的react-native-step-indicator组件依赖了已被废弃的React.PropTypes,但你的React Native/React版本已经移除了这个内置的PropTypes对象(React从v15.5开始就把PropTypes移到了单独的prop-types包中,新版本的React Native默认集成的React版本都符合这个要求)。

下面是两种可靠的解决方法:

方法一:用patch-package给组件打补丁(推荐)

这种方法不需要替换组件,而是修改库的依赖逻辑,并且能持久化修改(不会被npm install覆盖):

  1. 先安装prop-types和patch-package:
# npm 版本
npm install prop-types --save
npm install patch-package postinstall-postinstall --save-dev

# yarn 版本
yarn add prop-types
yarn add patch-package postinstall-postinstall --dev
  1. 找到node_modules/react-native-step-indicator/src/StepIndicator.js文件,修改顶部的导入语句:
    原代码:
import React, { Component, PropTypes } from 'react';

修改为:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
  1. 生成补丁文件:
npx patch-package react-native-step-indicator

执行后会在项目根目录生成patches/react-native-step-indicator+[版本号].patch文件,记得把这个文件夹提交到你的版本控制系统。

  1. 最后,在package.json的scripts里添加postinstall脚本,确保其他人安装依赖后自动应用补丁:
"scripts": {
  // ... 其他脚本
  "postinstall": "patch-package"
}

方法二:替换为维护活跃的替代组件

如果react-native-step-indicator已经很久没有更新(比如超过2年),可以考虑替换成更活跃的库,比如:

  • react-native-paper的ProgressStepper:Material Design风格的步骤指示器,集成度高
  • react-native-linear-gradient-step-indicator:支持渐变样式的步骤组件

替换后按照新组件的文档集成即可,避免后续再遇到类似的废弃API问题。

另外,你可以检查下package.json里的react和react-native版本,确认确实是在v15.5+的React版本范围内,这也能验证我们的问题分析。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:27:07