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

React Native 0.72.4安装@tensorflow/tfjs-react-native 0.8.0的依赖兼容问题解决

React Native 0.72.4 适配 @tensorflow/tfjs-react-native@0.8.0 版本兼容解决方案

解决思路1:降级expo-gl到依赖要求的版本范围

@tensorflow/tfjs-react-native@0.8.0的peer依赖明确指定expo-gl需为^7.0.0,因此直接降级相关包到兼容版本:

  • 先卸载当前高版本的expo包:
    npm uninstall expo-gl expo-gl-cpp
    
  • 安装适配的7.x版本:
    npm install expo-gl@~7.2.0 expo-gl-cpp@~11.0.0
    
  • 最后安装目标tfjs-react-native包:
    npm install @tensorflow/tfjs-react-native@0.8.0
    

解决思路2:跳过peer依赖检查(不推荐,仅临时应急)

如果不想降级expo-gl,可以通过npm参数强制忽略peer依赖冲突完成安装:

npm install @tensorflow/tfjs-react-native@0.8.0 --legacy-peer-deps

注意:这种方式可能导致运行时出现GL相关兼容性报错,若出现异常建议优先使用思路1。

适配后的package.json依赖示例

{
  "name": "your-rn-project",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.72.4",
    "@tensorflow/tfjs": "4.11.0",
    "@tensorflow/tfjs-react-native": "0.8.0",
    "expo-gl": "~7.2.0",
    "expo-gl-cpp": "~11.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "metro-react-native-babel-preset": "0.76.8"
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 18:45:12