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

求助:Expo React Native中ViewPropTypes移除错误的解决方法

解决React Native中ViewPropTypes已移除的错误

错误信息

ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'

问题原因

你使用的React Native 0.69.5(对应Expo 46)已官方移除ViewPropTypes API,但项目中部分老旧依赖库仍在从react-native导入该API,导致冲突报错。从你的package.json来看,以下依赖是主要嫌疑:

  • react-native-flexi-radio-button@0.2.2(长期未更新)
  • react-native-snap-carousel@3.9.1(已停止维护)
  • react-native-swiper@1.6.0(旧版本未适配新RN)
  • react-navigation@4.4.4(与你安装的v5版本冲突)
  • rn-sliding-up-panel@2.4.5(未适配RN 0.69+)

解决方案

方案1:临时兼容修复(快速解决)

通过安装兼容包并配置Babel,让旧库自动使用新的ViewPropTypes来源:

  1. 安装依赖包
npm install deprecated-react-native-prop-types babel-plugin-module-resolver --save
# 或用yarn
yarn add deprecated-react-native-prop-types babel-plugin-module-resolver
  1. 修改babel.config.js
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['module:metro-react-native-babel-preset'],
    plugins: [
      'react-native-reanimated/plugin',
      [
        'module-resolver',
        {
          alias: {
            'ViewPropTypes': 'deprecated-react-native-prop-types',
          },
        },
      ],
    ],
  };
};
  1. 清除缓存重启项目
expo r -c

方案2:替换过时依赖(长期稳定)

临时修复只是权宜之计,替换不再维护的依赖才能彻底解决问题:

  • react-native-flexi-radio-button → 改用@react-native-community/radio-button或自定义实现单选按钮
  • react-native-snap-carousel → 替换为react-native-reanimated-carousel或expo-swiper
  • react-native-swiper → 改用react-native-swiper-flatlist(Expo兼容)
  • react-navigation@4.x → 完全移除,统一使用已安装的@react-navigation/native v5版本,避免版本冲突
  • rn-sliding-up-panel → 改用你已安装的react-native-modalize,功能一致且适配新版本RN

额外检查

运行以下命令检查所有依赖与Expo 46的兼容性,根据提示修复:

expo doctor

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 23:10:55