如何解决使用AsyncStorage(已弃用)警告的问题?使用社区(正确)库

时间:2019-08-20 16:43:12

标签: react-native warnings asyncstorage

我正在使用@ react-native-community / async-storage并继续收到此警告:

/var/www/html/module.php /home/www/html/module.php

这是我的package.json:

Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage

我已经删除了node_modules,并删除yarn.lock并重新安装。另外,我查看了所有依赖项(如在此问题中建议的How to remove 'Warning: Async Storage has been extracted from react-native core...'?),但它们都不使用已弃用的异步存储包。

您对如何解决此警告有任何建议吗?

----编辑: 我被问到如何导入AsyncStorage。我只在一个名为storage-helpers的文件中的一个地方进行此操作:

{
  "name": "mobile_app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@aws-amplify/pushnotification": "^1.0.32",
    "@react-native-community/async-storage": "^1.6.1",
    "aws-amplify": "^1.1.32",
    "aws-amplify-react-native": "^2.1.15",
    "buffer": "^5.3.0",
    "moment": "^2.24.0",
    "react": "16.8.3",
    "react-native": "0.59.9",
    "react-native-ble-plx": "^1.0.3",
    "react-native-calendars": "^1.208.0",
    "react-native-check-box": "^2.1.7",
    "react-native-dialog": "^5.6.0",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-indicators": "^0.13.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-modal-datetime-picker": "^7.5.0",
    "react-native-modalbox": "^1.7.1",
    "react-native-swipeable-row": "^0.8.1",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^3.11.0",
    "react-redux": "^7.1.0",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/runtime": "^7.4.5",
    "babel-jest": "^24.8.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.54.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}

4 个答案:

答案 0 :(得分:2)

在查看依赖项列表时,列表@aws-amplify/pushnotification中的第一个使用了AsyncStorage中的react-native

您会看到here导入了AsyncStorage。下面是确切的行:

import { NativeModules, DeviceEventEmitter, AsyncStorage, PushNotificationIOS, Platform, AppState } from 'react-native';

这就是您收到警告的原因,这是由于使用AsyncStorage

5月份曾有一个关于此问题的问题,但是此后被标记为已关闭。您可以看到问题here


似乎@aws-amplify/core也使用了AsyncStorage中的react-native

您可以看到它正在RNComponents here和StorageHelper here中使用。


您最好的做法是分叉存储库,并修复AsyncStorage的所有实例以使用正确的版本,或解决问题。


始终值得仔细检查您的依赖项,以查看其实际使用的内容。有时,只需搜索他们已安装的内容或github中的内容即可。

答案 1 :(得分:1)

确保您使用的是正确的导入:

import AsyncStorage from '@react-native-community/async-storage';

答案 2 :(得分:0)

检查您的依赖项之一是否使用了异步存储,并且它们是直接从react导入的。

答案 3 :(得分:0)

似乎异步存储已转移到新组织

enter image description here

试试 npm i @react-native-async-storage/async-storage

import AsyncStorage from '@react-native-async-storage/async-storage';