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

Created on 15 Feb 2017  路  21Comments  路  Source: realm/realm-js

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


}

T-Help

Most helpful comment

realm is not usable..
as of "realm": "^1.0.2"

All 21 comments

Hey @jjhesk,

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

userde-iMac:rnfirst$ react-native link realm
rnpm-install info Android module realm is already linked 
rnpm-install info iOS module realm is already linked 

@fealebenpae no use

That might be because you initially ran rnpm link :/ Could you try starting over?

its the same.

I removed rnpm globally. removed realm. install realm by npm

i got that from the package.json

 "realm": "^1.0.2"

and i did this

userde-iMac:rnfirst $ react-native link realm
rnpm-install info Linking realm android dependency 
rnpm-install info Android module realm has been successfully linked 
rnpm-install info iOS module realm is already linked 

My other suggestion is to completely restart the React Native packager and clean its watchman caches.

Also, does it work when you disable Remote JS Debugging in your app?

@fealebenpae i saw the glitch maybe. I restart everything and the app compile and build correctly. and then the dashscreen poped up and then disappeared. I reopen the app again and i see this..

Unknown execution context

how to clean watchman cache?

realm is not usable..
as of "realm": "^1.0.2"

@jjhesk try watchman watch-del-all and npm cache clean

@kristiandupont i followed the steps. closed the simulator, close the console debugger, and exit. watchman clear, cache clean. And now I restart the app by react-native run-ios and I still get the same debugHosts error.
as of "realm": "^1.0.2", rn: 0.41.2, and iOS10.2.
Here is the conclusion:
with js remote debugger: I will get debugHosts error
without js remote deubugger: I will get Unknown execution content

@jjhesk Did you solve this? I'm running into the same problem.

Are you using the latest version of Realm (1.1.1)? @MrHubble, are you getting the debugHosts or the "Unknown execution context" error?

I'm using Realm 1.1.1

I saw the same behaviour as jjhesk:

with js remote debugger: I will get debugHosts error
without js remote deubugger: I will get Unknown execution content

It is now resolved for me. I believe I found the solution in another issue that was similar to:

  • stop the package manager
  • yarn cache clean
  • yarn start

and then running the app again.

Sorry if that's a bit vague but it's still a new world to me and I can't remember the exact fix.

Well, that's better than nothing. @jjhesk, are you still having problems?

Have the same problem. I did:

  • stop the package manager
  • yarn cache clean
  • yarn start

Still having this issue

I have solved issue for myself by adding libRealmJS.a and libRealmReact.a to Linked Frameworks and Libraries. I'm using project with Cocoapods.

Just to share my solution of 'Unknown execution context' in JS remote debugger mode.

As realm check userAgent for Chrome DevTools here, just to check your navigator.userAgent has Chrome.
If turning on Device Mode for Chrome DevTools, the userAgent will be device user agent such as iPhone's user agent, and 'Unknown execution context' happens.

I have the same problem.
"react-native": "^0.46.2",
"realm": "^1.10.0",
Android 7.0 device
Files "MainApplication.java", "build.gradle" and "settings.gradle" are correct.
But not every running will encounter this issue. Most time it is good for the first load when android is connected to the PC.

Same here, using
"react-native": "0.46.0",
"realm": "^1.10.1"
on iOS/android can't solve it.
@borapop i'm not using cocoapods and i can't see these files inside my Xcode project.

same problem, fixes above have not worked for me so far

work for me:

  • uninstall the app of the emulator
  • react-native run-ios
  • laugh

@illu9000 : After doing so it starts to throw exception instead of read screen error. When run in xcode app crash on
node_modules/realm/vendor/json.hpp, line 4012.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gwanjar picture gwanjar  路  3Comments

emrehayirci picture emrehayirci  路  3Comments

jmartindivmedianet picture jmartindivmedianet  路  3Comments

camslaz picture camslaz  路  4Comments

timanglade picture timanglade  路  3Comments