Undefined不是对象(评估'RCTAsyncStorage.multiMerge'(React-native-asyncstorage)

Yus*_*aji 7 react-native asyncstorage expo

我从这里遇到与react-native-asyncstorage相关的问题:https://facebook.github.io/react-native/docs/asyncstorage.html

运行时react-native run-ios,出现以下错误: 在此输入图像描述

我使用的是react-native 0.52.0,这个问题可能是由于react-native-asyncstorage的依赖:

react-native-asyncstorage@1.0.0需要一个peer- react-native@^0.47.2,但没有安装.您必须自己安装对等依赖项.

奇怪的是它适用于Android,但不适用于iOS和iOS模拟器.

有人可以帮忙吗?

编辑

我想补充一些可能有用的要点:

  • 我用Expo进行开发,
  • 我在我的代码中评论了每个AsyncStorage,但问题仍然存在,
  • 正如评论中所述,这是我的AsyncStorage代码的剪切代码

-

import { AsyncStorage } from 'react-native';
export async function SetItem(strKey, objValue) {
    try {
        if (typeof(objValue) === 'string') {
            await AsyncStorage.setItem(strKey, objValue);
        }
        else {
            await AsyncStorage.setItem(strKey, JSON.stringify(objValue));
        }
    } 
    catch(error){
        console.log(error);
    }
}
Run Code Online (Sandbox Code Playgroud)

zvo*_*ona -1

正如文档中所述:注意:并非所有本机实现都支持此功能,因此您可能会遇到错误。

也可能是您正在使用的Reactotron(根据堆栈跟踪)导致了这种情况。首先尝试禁用它?

您是否有自定义实现AsyncStorage(例如: https: //www.npmjs.com/package/react-native-asyncstorage)?如果是这样,请将其取下,除非有特定原因使用它(请在问题中详细说明)

但一般来说,您可以使用React Native Simple Store及其update方法。

或者,您可以使用lodash.merge编写自己的函数。

如果即使注释掉所有 AsyncStorage 代码、删除可能的自定义依赖项并取消 Reactotron,问题仍然存在,并且您无法找到自己编写 multiMerge 的方法,请更新您的问题并向我告知此答案。