Expo集成react-native-video报错:RCTVideo未在UIManager中找到
解决
requireNativeComponent: "RCTVideo" was not found in the UIManager错误 问题原因
react-native-video是纯React Native原生模块,在Expo Managed Workflow(非裸项目)中无法直接使用——Expo没有预打包该模块的原生代码,因此运行时找不到对应的RCTVideo组件。
解决方法一:使用Expo官方expo-av组件替代(推荐)
Expo官方提供的expo-av完全适配Expo环境,无需处理原生配置:
- 安装依赖:
npx expo install expo-av
- 替换原有代码,使用
expo-av提供的Video组件:
import { Video } from 'expo-av'; export default function YourComponent() { return ( <Video source={{ uri: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" }} style={{ width: '100%', height: 300 }} useNativeControls resizeMode="contain" shouldPlay /> ); }
解决方法二:转为裸工作流并配置react-native-video
若必须使用react-native-video,需将Expo项目转为裸工作流,手动配置原生代码:
- 执行预构建命令,将Managed项目转为裸项目:
npx expo prebuild
- 安装
react-native-video:
npm install react-native-video
- 平台专属配置:
- iOS:进入iOS目录执行pod安装
cd ios && pod install && cd ..
- Android:RN 0.60+版本无需额外配置,模块会自动链接
- 清除缓存并重启项目:
npx expo start --clear
内容的提问来源于stack exchange,提问作者Shaimaa
相关产品推荐
相关产品推荐

