我已经尝试过此屏幕截图中的建议
通过使用这一行代码
我要从import AsyncStorage from '../../../node_modules/@react-native-community/async-storage';
导入async-storage
的文件中的react-native
但是此路径无法解析,即该目录中不存在async-storage
。我还尝试通过运行async-storage
来安装yarn add async-storage
(即使它已经安装了),但是在前面提到的目录中没有任何显示
最佳答案
有两种方法可以执行此操作。
AsyncStorage
。这将删除警告并解决问题。 AsyncStorage
中删除了react-native
,就会引起您的问题。我不会这样做,因为这实际上是解决问题的第一种方法。 Note you can get this warning if you are using a dependency that uses AsyncStorage and still imports it the old way from react-native. Installing AsyncStorage won’t fix the error. You will need to look through your dependencies’ dependencies to find out which one is causing it.
This means actually going through the code of each your dependencies to see if they use
AsyncStorage
. Searching through your node modules or on the dependency's Github usually is sufficient but it can take some time to find it.Once you have found out which one is causing it, you should open an issue or create a PR with a fix on the dependency’s repo. At this point suppressing the warning is all you can do until it is fixed.
安装AsyncStorage
npm
或yarn
安装:选择通常使用的方法
npm i @react-native-community/async-storage
要么yarn add @react-native-community/async-storage
链接依赖项(如果您使用的是0.60+,则不必这样做,因为它具有Autolinking)react-native link @react-native-community/async-storage
然后像这样导入它,并像以前一样使用它。import AsyncStorage from '@react-native-community/async-storage';
您可以通过查看here了解更多信息停止警告。
您可以使用以下命令禁止YellowBox警告
import {YellowBox} from 'react-native';
然后您可以添加以下内容YellowBox.ignoreWarnings(['Warning: Async Storage has been extracted from react-native core']);
我通常在App.js
中执行此操作,因此很容易跟踪我隐藏了哪些内容。它不会从您的控制台中删除该警告,但会删除与该错误相关的所有YellowBox警告。 但是,由于可以正确安装依赖项,因此我不会在这种情况下执行此操作。
世博用户
目前,Expo仍从
AsyncStorage
导入react-native
,因此,您可能仍然会遇到警告。我相信出于向后兼容的原因,它仍然以这种方式导入它。快速浏览Expo仓库显示,有很多实例在使用它,如您所见here。在这种情况下,您唯一的选择是禁止显示警告。根据Expo功能的要求,它是currently in progress,因此希望可以将其不久后添加到Expo中。博览会更新
截至2020年6月:可以在Expo管理的应用程序中安装
@react-native-community/async-storage
v1.11.0。希望这将导致较少的警告出现,因为依赖项已转换为导入异步存储的新方法。
关于react-native - 如何删除 'Warning: Async Storage has been extracted from react-native core…'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55311228/