realm-js: [iOS] Cannot read property 'debugHosts' of undefined

Hi There, i just did a vanilla installation for the realm specified here. However, i got this exception. I was not able to launch it at all. Its very similar to #527 and I read #392 for the fix but it doesnt work…

Steps Followed:

react-native init npm install --save realm rnpm link realm react-native run-ios

react-native: 0.41.2 ios: 10.0 osx 10.12.1 realm: 1.0.2

I have the below installation of the implementation. The library react-native-database is based on this repo.

/**
 * Created by hesk on 14/2/2017.
 */
import axios from 'axios';
import Database from 'react-native-database';
import S from 'react-native-storage';
import {AsyncStorage} from 'react-native';
import C from './constants';
import L from 'lodash';
const instance_ns = new S({
    size: 1000, storageBackend: AsyncStorage, enableCache: true, defaultExpires: 1000 * 3600 * 24,
});
const instance = axios.create({
    baseURL: C.DOMAIN,
    timeout: 60000,
    headers: {'X-Custom-Header': 'foobar'}
});
class User {
    add_user(user_id: string, _email: string, _firstName: string, _lastName: string) {
        database.write(() => {
            database.create('User', {id: user_id, email: _email, firstName: _firstName, lastName: _lastname})
        });
        settings.set(C.pref.USER_ID, user_id);
    }
}
User.schema = {
    name: 'User',
    primaryKey: 'id',
    properties: {
        id: 'string',
        username: {type: 'string', default: 'placeholderUsername'},
        lastLogin: {type: 'date', optional: true},
        firstName: {type: 'string', optional: true},
        lastName: {type: 'string', optional: true},
        email: {type: 'string', optional: true},
    },
};
class Basemap {

    resultFromSingleEntry(data) {
        if (L.isObject(data)) {
            database.write(() => {
                database.create('User', {
                        id: data.id,
                        fast_id: data.fast_id,
                        complete: data.complete,
                        owner: data.owner,
                        folder_base_name: data.folder_base_name,
                        secret_base_map_file: data.secret_base_map_file,
                        rename_file: data.rename_file,
                        mid_size: data.mid_size,
                        price: data.price,
                        baseprice: data.baseprice,
                        license_price: data.license_price,
                        factory_shared: data.factory_shared,
                        printed_shared: data.printed_shared,
                        print_limit: data.print_limit,
                        estprice: data.estprice,
                        currency: data.currency,
                        image_type: data.image_type,
                        createtime: data.createtime,
                        updatetime: new Date()
                    },
                )
            });
        }
    }
}
Basemap.schema = {
    name: 'Basemap',
    primaryKey: 'id',
    properties: {
        id: 'string',
        fast_id: 'string',
        complete: 'float',
        owner: 'string',
        folder_base_name: 'string',
        secret_base_map_file: 'string',
        rename_file: 'string',
        mid_size: 'string',
        price: 'int',
        baseprice: 'int',
        license_price: 'int',
        factory_shared: 'int',
        printed_shared: 'int',
        print_limit: 'int',
        estprice: 'int',
        currency: 'string',
        image_type: 'string',
        createtime: 'date',
        updatetime: 'date'
    }
};
class Setting {
    get ageSeconds() {
        return Math.floor((Date.now() - this.birthday.getTime()));
    }

    get age() {
        return ageSeconds() / 31557600000;
    }
}
Setting.schema = {
    name: 'Setting',
    primaryKey: 'key',
    properties: {
        key: 'string',
        value: 'string',
    },
};
const schema = {schema: [Basemap, Setting, User], schemaVersion: 1};
const database = new Database(schema);
const settings = new Settings(database);
let self;
export default class Axo {
    constructor(props) {
    }

    conf = {};

    static get getConfig() {
        return Axo.conf;
    }

    static _startApp(cb) {
        if (self == null) {
            self = new Axo();
        } else {
            self = this;
        }
        instance_ns
            .load({key: C.pref.INIT, autoSync: true, syncInBackground: true})
            .then(ret => {
                console.log("sync return", ret);
                self.conf = ret;
                cb();
            }).catch(err => {
            // any exception including data not found
            console.warn(err.message);
            switch (err.name) {
                case 'NotFoundError':
                    self._checkNetworkOnStart();
                    break;
                case 'ExpiredError':
                    self._checkNetworkOnStart();
                    break;
            }
        });

    }

    _checkNetworkOnStart() {
        let self = this;
        instance.get(C.uri_init).then(function (res) {
            if (res) {
                console.log("network successfully loaded", res);
                self.conf = ret;
                instance_ns.save({key: C.pref.INIT, rawData: res, expires: 1000 * 3600});
            }
        }).catch(err => {
            console.warn(err.message);
            switch (err.name) {
                case 'NotFoundError':

                    break;
                case 'ExpiredError':

                    break;
            }
        });
    }


}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

realm is not usable… as of “realm”: “^1.0.2”

Hey @jjhesk,

Try calling react-native link realm instead of rnpm link realm.