react-native - Realm 错误 - _constructor 必须是 'function' 类型,得到(未定义)

标签 react-native mobile realm local-storage realm-mobile-platform

我正在尝试使用我的 React Native 应用程序在本地设置 Realm DB,但似乎存在一个我无法找出原因的错误。我已关注 documentation和指南here .

我的代码。

import Realm from 'realm';

export const ConfigSchema = {
    name: 'Config',
    primaryKey: 'key',
    properties: {
        key: 'string',
        value: 'string'
    }
};

export const databaseOptions = {
    path: 'myappreactnative.realm',
    schema: [ConfigSchema],
    schemaVersion: 0
};

export const insertNewConfig = (newConfig) => new Promise((resolve, reject) => {
    Realm.open(databaseOptions).then(realm => {
        // realm.create('Config', newConfig);
        // resolve(newConfig);
        console.log(realm);
    }).catch((error) => reject(error))
});

我打电话 insertNewConfig从这里,
let config = {
    key: 'instanceUrl',
    value: 'myurl.domain.value'
};

insertNewConfig(config).then((result) => {
    console.log(result);
}).catch((error) => {
    console.log(error);
});

this.props.navigation.navigate('Login', {});

错误在 Realm.open(databaseOptions)线。首先,我认为错误出在 realm.create但后来才意识到原来的路线。

显示的错误是这样的。
Error: _constructor must be of type 'function', got (undefined)
    at sendRequest (rpc.js:263)
    at Object.createRealm (rpc.js:62)
    at new Realm (index.js:102)
    at Function.open (extensions.js:110)
    at eval (eval at <anonymous> (MetroClient.js:63), <anonymous>:29:22)
    at tryCallTwo (core.js:45)
    at doResolve (core.js:200)
    at new Promise (core.js:66)
    at insertNewConfig (eval at <anonymous> (MetroClient.js:63), <anonymous>:28:12)
    at Object.SelectInstanceScreen._this.continueLogin [as onPress] (eval at <anonymous> (MetroClient.js:63), <anonymous>:74:37)

好像是open() function 必须作为函数调用(_constructor 必须是“function”类型),但很明显 open()被称为函数。
提前致谢。

最佳答案

我认为可能是上一个版本 (2.18.0) 上的一个错误,尝试降级到 2.16.0 它将起作用。

关于react-native - Realm 错误 - _constructor 必须是 'function' 类型,得到(未定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52716115/

相关文章:

arrays - Swift Realm [[String]] 对象

node.js - 在 iOS React Native 应用程序中实现 gRPC

ios - React Native WebView 与 iOS 和 domStorage

react-native - 如何在 React Native 0.57 中使用带有装饰器的 MobX?

javascript - 如何在 TabNavigator 上显示图标以响应 native

networking - 移动网络中的持久 TCP 连接?

JavaScript getElementById 无法在手机上运行

ios - 父子 Realm

python - 如何检查用户是否在 Django 1.9 中使用移动设备?

ios - Objc 等待 REALM 对象存在