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

使用@tensorflow/tfjs-react-native是否必须依赖已废弃的Async Storage?

是否必须为@tensorflow/tfjs-react-native使用已废弃的@react-native-community/async-storage?

问题背景

@tensorflow/tfjs-react-native仍依赖已废弃的@react-native-community/async-storage,导致项目出现如下报错:

Unable to resolve "@react-native-community/async-storage" from "node_modules/@tensorflow/tfjs-react-native/dist/async_storage_io.js"

项目的package.json配置如下:

{
  "name": "objectdetect",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.17.11",
    "@tensorflow/tfjs": "^4.2.0",
    "@tensorflow/tfjs-react-native": "^0.1.0-alpha.1",
    "expo": "~48.0.0",
    "expo-camera": "^13.2.1",
    "expo-gl": "^12.4.0",
    "expo-gl-cpp": "^11.4.0",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-native": "0.71.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

解答

不需要必须使用已废弃的@react-native-community/async-storage版本,可以通过别名映射的方式让依赖库指向你已安装的新版Async Storage,具体操作如下:

  • 在项目根目录创建或修改metro.config.js,添加别名映射配置:
const { getDefaultConfig } = require('@expo/metro-config');

const config = getDefaultConfig(__dirname);

// 为废弃的包名映射到新版包
config.resolver.extraNodeModules = {
  '@react-native-community/async-storage': require.resolve('@react-native-async-storage/async-storage'),
};

module.exports = config;
  • 保存配置后,重启Expo开发服务器,即可解决模块解析报错。

另外,由于你使用的是@tensorflow/tfjs-react-native的alpha版本,后续官方大概率会在正式版本中替换依赖为新版的@react-native-async-storage/async-storage,可以持续关注版本更新。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 11:57:30