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

启动React Native项目遇异常:TypeError: _MaterialIcons.default.propTypes.style未定义

解决React Native中MaterialIcons未定义及AppRegistry错误

问题背景

安装react-native-video-player后,修复拼写错误重启项目出现以下错误:

TypeError: undefined is not an object (evaluating '_MaterialIcons.default.propTypes.style')

同时Metro终端出现:

ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)...

虽未直接使用MaterialIcons,且尝试了常规清理重装手段,问题仍存在。

解决方案

1. 确认间接依赖

先检查react-native-video-player是否间接依赖了react-native-vector-icons:

# npm用户
npm ls react-native-vector-icons
# yarn用户
yarn list react-native-vector-icons

如果输出显示该依赖存在,说明是第三方包的隐式依赖导致问题。

2. 手动安装并链接react-native-vector-icons

即使未直接使用,也需要安装该依赖以满足第三方包的需求:

# npm安装
npm install react-native-vector-icons
# yarn安装
yarn add react-native-vector-icons
  • iOS端:进入ios目录执行pod安装
    cd ios && pod install && cd ..
    
  • Android端:在android/app/build.gradle文件末尾添加:
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
    

3. 彻底清除Metro缓存

常规清理可能不彻底,执行以下命令重置缓存并重启Metro:

npx react-native start --reset-cache

保持Metro运行,重新启动项目。

4. 清理平台端深层缓存

  • iOS:打开Xcode,进入Preferences > Locations > Derived Data,点击箭头打开文件夹,删除当前项目对应的Derived Data文件夹,再重新编译。
  • Android:进入android目录执行清理命令:
    cd android && ./gradlew clean && cd ..
    

5. 降级react-native-video-player版本

如果当前版本与你的React Native版本不兼容,尝试安装旧版本:

# 示例:安装0.10.1版本,可根据自身RN版本调整
npm install react-native-video-player@^0.10.1

原因说明

react-native-video-player内部可能使用了react-native-vector-icons/MaterialIcons组件,但未在依赖声明中明确要求,导致安装过程中该依赖未被正确初始化,进而引发模块加载失败,最终触发AppRegistry错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 00:54:30