Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Cannot read property 'debugHosts' of undefined #868

Closed
jjhesk opened this issue Feb 15, 2017 · 21 comments
Closed

[iOS] Cannot read property 'debugHosts' of undefined #868

jjhesk opened this issue Feb 15, 2017 · 21 comments
Labels

Comments

@jjhesk
Copy link

jjhesk commented Feb 15, 2017

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


}

@fealebenpae
Copy link
Member

Hey @jjhesk,

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

@jjhesk
Copy link
Author

jjhesk commented Feb 15, 2017

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

@fealebenpae
Copy link
Member

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

@jjhesk
Copy link
Author

jjhesk commented Feb 15, 2017

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 

@fealebenpae
Copy link
Member

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?

@jjhesk
Copy link
Author

jjhesk commented Feb 15, 2017

@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?

@jjhesk
Copy link
Author

jjhesk commented Feb 16, 2017

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

@kristiandupont
Copy link
Contributor

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

@jjhesk
Copy link
Author

jjhesk commented Feb 16, 2017

@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

@MrHubble
Copy link

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

@kristiandupont
Copy link
Contributor

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

@MrHubble
Copy link

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.

@kristiandupont
Copy link
Contributor

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

@borapop
Copy link

borapop commented Mar 17, 2017

Have the same problem. I did:

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

Still having this issue

@borapop
Copy link

borapop commented Mar 17, 2017

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

@Kudo
Copy link

Kudo commented Apr 6, 2017

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.

@adyanced
Copy link

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.

@geniuscd
Copy link

geniuscd commented Aug 6, 2017

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.

@AdamLenda
Copy link

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

@felimoles
Copy link

work for me:

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

@bhatti-waqas
Copy link

@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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests