未定义不是对象(评估'RCTAsyncStorage.multiMerge'(React-native-asyncstorage) [英] Undefined is not an object (evaluating 'RCTAsyncStorage.multiMerge' (React-native-asyncstorage)

查看:144
本文介绍了未定义不是对象(评估'RCTAsyncStorage.multiMerge'(React-native-asyncstorage)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了与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需要一个对等体 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);
    }
}

解决方案

就像文档中所说的那样:注意:并非所有本机实现都支持此操作,您可能因为错误而运行

可能是您使用的 Reactotron (根据堆栈跟踪)导致了此情况.尝试先禁用它吗?

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

但是通常,您可以使用 React Native Simple Store ,它是update方法.

或者然后您可以使用 lodash.merge 编写自己的函数.. >

如果即使注释掉所有AsyncStorage代码,删除可能的自定义依赖项并删除Reactotron仍然存在问题,并且您找不到自己编写multiMerge的方法,请更新您的问题并对这个答案ping me.

I am having an issue related to react-native-asyncstorage from here: https://facebook.github.io/react-native/docs/asyncstorage.html

When I run react-native run-ios, the following error appears:

I am using react-native 0.52.0 and this problem may be due to the dependency of react-native-asyncstorage:

react-native-asyncstorage@1.0.0 requires a peer of react-native@^0.47.2 but none is installed. You must install peer dependencies yourself.

The odd thing is it works fine for Android, but not for both iOS nor iOS emulator.

Can someone help?

EDIT

I would like to add some points that maybe useful:

  • I use Expo for development,
  • I have commented every AsyncStorage in my code, but the problem still persist,
  • As asked in the comment, here is the snipped code of my AsyncStorage code

-

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);
    }
}

解决方案

Like said in the documentation: NOTE: This is not supported by all native implementations, you're probably running in an error because of this.

It may also be Reactotron you're using (according to the stack trace) that causes this. Try disabling it at first?

Are you having a custom implementation of AsyncStorage (like: https://www.npmjs.com/package/react-native-asyncstorage)? If so, take it off unless there's a specific reason to use it (please elaborate in the question)

But in general, you could for instance use React Native Simple Store and it's update method.

Or then you could write your own function with lodash.merge.

If problem persists even with commenting out all the AsyncStorage code, removing possible custom dependencies and taking off Reactotron, and you can't find a way to write multiMerge by yourself, update your question and ping me on this answer.

这篇关于未定义不是对象(评估'RCTAsyncStorage.multiMerge'(React-native-asyncstorage)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆