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

安装React Native音视频库时遇“无法解析模块”错误求解决

解决react-native-video-player模块无法解析的问题
  • 确认依赖安装状态
    先打开项目根目录的package.json,检查是否存在react-native-video和react-native-video-player这两个依赖。如果没有,执行以下命令重新安装:

    npm install react-native-video react-native-video-player --save
    # 用yarn的话执行:yarn add react-native-video react-native-video-player
    

    要是已经安装过,直接删除依赖文件和锁文件后重装:

    rm -rf node_modules package-lock.json yarn.lock
    npm install
    # 或 yarn install
    
  • 清除Metro缓存
    Metro缓存可能导致模块识别异常,执行命令重置缓存:

    npx react-native start --reset-cache
    

    之后重启你的React Native开发服务。

  • 核对路径与导入语句

    • 确保安装命令是在项目根目录执行的,不是子文件夹下。
    • 确认导入语句import VideoPlayer from 'react-native-video-player';正确,可查看node_modules/react-native-video-player里的README确认默认导出是否为VideoPlayer。
  • 检查版本兼容性
    查看node_modules/react-native-video-player/package.json里的peerDependencies,确认你的React Native版本是否符合要求。如果版本不匹配,安装适配的指定版本:

    npm install react-native-video-player@x.x.x --save
    

    (把x.x.x替换为兼容你RN版本的具体版本号)

  • 手动链接依赖(旧版RN适用)
    若你的React Native版本低于0.60,需要手动链接依赖:

    npx react-native link react-native-video
    npx react-native link react-native-video-player
    

    0.60+版本支持自动链接,可跳过此步,但自动链接失效时也可以尝试手动链接后重新编译。

  • 重新编译项目
    关闭当前的打包进程,重新运行项目:

    npx react-native run-android
    # iOS项目执行:npx react-native run-ios
    

内容的提问来源于stack exchange,提问作者Nguyễn Hiếu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 23:05:25