Expo(Web)环境下无法运行Lottie组件的问题求助
问题解决指南
问题原因
你遇到的仓库不存在报错,确实是因为@lottiefiles/react-lottie-player的GitHub仓库地址变更或已迁移,导致expo install命令无法拉取到包资源。同时Expo官方文档的简易说明可能存在混淆——Expo自身集成的Lottie组件其实是expo-lottie,而非第三方的@lottiefiles/react-lottie-player。
解决方案
方案一:使用Expo官方集成的Lottie组件(推荐)
这是最适配Expo项目的方式:
- 清理残留的错误依赖(如果之前尝试安装过):
npm uninstall @lottiefiles/react-lottie-player - 安装Expo官方的Lottie包:
npx expo install expo-lottie - 在代码中正确导入并使用:
import { LottieView } from 'expo-lottie'; // 示例用法 <LottieView source={require('./assets/animation.json')} autoPlay loop />
方案二:手动安装第三方Lottie Player包
如果确实需要使用@lottiefiles/react-lottie-player,可以绕过expo install直接用npm安装,同时确保使用HTTPS而非SSH拉取:
- 执行以下命令安装:
npm install @lottiefiles/react-lottie-player --registry=https://registry.npmjs.org/ - 安装完成后,按照包的官方文档导入使用即可。
内容的提问来源于stack exchange,提问作者Univers3
相关产品推荐
相关产品推荐

