Reputation: 708
I am trying to setup Realm DB locally with my react native application but there seems to be an error that I cannot figure out a reason for. I have followed the documentation and the guide here.
My Code.
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))
});
I'm calling insertNewConfig
from here,
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', {});
The error is there at the Realm.open(databaseOptions)
line. First I though the error was with realm.create
but later realized the original line.
The error showing is like this.
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)
Seems that the open()
function must be called as a function (_constructor must be of type 'function') but it is obvious that open()
is called as a function.
Thanks in advance.
Upvotes: 8
Views: 1407
Reputation: 36
There are a few issues related to Node update and realm. Realm doesn't work with Node 10 and for your issue downgrading to 2.16 will resolve the issue.
Upvotes: 1
Reputation: 3142
I have changed package.json changed
from "realm": "ˆ2.16.0",
to "realm": "2.16.0",
And then execute npm install
or yarn
Solved it for me.
Upvotes: 1
Reputation: 162
It is related from last version of realm(v2.18.0). You should downgrade to 2.16.0.
After that, you can run this code for reset all packages;
watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache
Upvotes: 1
Reputation: 710
I think maybe is a bug on last release (2.18.0), try to downgrade to 2.16.0 it will works.
Upvotes: 6