Import Realm into a React Native project.
I should be able to import Realm and run the project in iOS with crashing.
The app crashes in release mode completely. The app crashes in debug mode if not using Chrome Debugger and I get this error on the screen:
Undefined is not a constructor (evaluating 'new XMLHttpRequest')
I get this repeating error in the console
"Must first create RPC session with a valid host".
I'm trying to import Realm into my React Native project and run in iOS. I've installed the npm and linked it. It crashes when I add the following line:
import Realm from 'realm';
Maybe I misinterpret:
crashes in debug mode if not using Chrome Debugger
but you can only debug React Native apps using Chrome.
I fixed this by downgrading Realm. In package.json, the line for realm is now:
"realm": "^1.11.1"
instead of:
"realm": "^2.4.1"
There has to be a better solution than downgrading to 1.11. Realm is on 2.8.
@kneth what he means is the error only springs when you're debugging. This is a pretty killer issue. Is it worth downgrading so much to solve it?
EDIT: Downgrading did not solve this issue for me. Request to reopen this ticket
@arshbot were you able to overcome this issue?
It works when I am remote debugging (:8081).
It does not work when not remote debugging.
@woodpav what about the production build?
The production build would crash immediately. start_wqthread or something like that. Also if I let the debug build sit there it would crash after a few minutes due to a Realm error "attach notification listener". So I had 3 crashes including the one initially mentioned. I was using a fresh install of Realm from npm and the only Realm code I had was import Realm from 'realm'; and a Realm.open(), realm.objects().filtered(). I'm afraid this is all the info I can provide as I had just added realm, got fed up, and switched to SQLite.
@sheva007 there is a way around this, and it is frustrating. I can't remember what I did but it was definitely a mix of uninstalling, reininstalling, relinking, resetting, etc until something clicked correctly and realm stopped fucking itself.
This really should be reopened @kneth
Thanks @woodpav & @arshbot for the help,
I tried also doing upgrade to react-native. So I had fresh gradle files, then i uaed reinstalling then relinking but it doesn't work.
In fresh app where I only have typescript & realm, it works.
Seems other packages maybe affecting it.
Seing this too, should be reopened
@Michaelvilleneuve @sheva007 @arshbot Any suggestions on how to reproduce this?
Honestly I have no idea. It just started happening and since then I can’t remove that error unless I activate chrome remote debugging
Thanks @bmunkholm for the re-open, I have tested realm with typescript in a fresh project and all was smooth, But when tried with the current existing project I get this error.
I only have 2 other packages needed linking in the native side:
react-native-vector-icons
react-native-svg
in Android I get "can't find variable Symbol"; while in ios "Undefined is not a constructor (evaluating 'new XMLHttpRequest')"
I wanted to use realm to replace PouchDB
Apart from realm, here are my dependencies:
"dependencies": {
"axios": "^0.18.0",
"i18n-js": "^3.0.11",
"lodash": "^4.17.10",
"pouchdb-adapter-asyncstorage": "^6.4.1",
"pouchdb-find": "^6.4.1",
"pouchdb-react-native": "^6.4.1",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-elements": "^0.19.1",
"react-native-modal": "^6.4.0",
"react-native-picker-select": "^4.2.1",
"react-native-progress": "^3.5.0",
"react-native-root-toast": "^3.0.1",
"react-native-snap-carousel": "^3.7.2",
"react-native-svg": "6.5.2",
"react-native-vector-icons": "^5.0.0",
"react-navigation": "^2.9.3",
"redux": "^4.0.0",
"rn-viewpager": "^1.2.9",
"tslib": "^1.9.0"
},
"devDependencies": {
"@types/i18n-js": "^3.0.0",
"@types/lodash": "^4.14.112",
"@types/pouchdb": "^6.3.2",
"@types/pouchdb-find": "^6.3.3",
"@types/react": "^16.3.14",
"@types/react-native": "^0.56.3",
"@types/react-native-snap-carousel": "^3.6.3",
"@types/react-navigation": "^2.0.11",
"eslint": "5.4.0",
"prop-types": "15.6.2",
"react-native-typescript-transformer": "1.2.10",
"tslint": "^5.9.1",
"tslint-eslint-rules": "^5.1.0",
"tslint-react": "^3.5.1",
"typescript": "^2.8.3"
}
@sheva007 I share these packages with you :
"dependencies": {
"react": "16.4.1",
"react-native": "0.55.3",
"react-native-vector-icons": "^5.0.0",
"react-navigation": "2.7.0",
"realm": "2.8.0",
},
"devDependencies": {
"eslint": "4.19.1",
},
I'm not sure why there would be a relation to them but still.
One thing I might have done before breaking realm is linking react-native-camera maybe linking any library would have broken it ?
By the way, something similar happens on Android. This message is iOS only but here is the error for both platforms :
undefined is not a constructor (evaluating 'new XMLHttpRequest()')
makeRequest - rpc.js:204:22
Can't find variable : Symbol
<unknown> - constants.js:30:24
same issue.
after add 'web3' to my project follow this,
run ios crash:
undefined is not a constructor (evaluating 'new XMLHttpRequest()')
Downgrading realm works for me, and I found the problem happened after version 2.0.2:
"realm": "2.0.2" works
"realm": "2.0.3" crash
@sheva007 I hope it helps
So I've taken another swing at it and I've gotten further than before. I'll try to recount exactly what I've done but it was a lot of back and forth so my details may not be perfect. I installed Realm v2.17.0 and I was getting the same errors @Michaelvilleneuve mentioned until I upgraded my project to RN 0.56 and React to 16.4.1. Then I started getting errors about debugHosts and remote debugging. I tried @JamesZhange advice and it works when I use Realm v2.0.2. I had to follow the manual steps for linking Android as well. So far it seems to be working. The only side effect I seem to have now is that chrome debugging is not working on Android simulator (The device screen is all white and the debugger window just loads infinitely).
I have the same issue too, any updates? (React native 0.54.5, Realm v2.17.0, Android)
I still have the same error, did anyone solve it?
"realm":"2.24.0",
"react-native":0.55.3"
also facing this error, does anybody have any solutions?
We have just released v2.25.0. Please try to upgrade.
error is not gone after realm upgrade.
my thoughts that there was something wrong with our native builds. i tried to setup realm on fresh CRNA with RN 0.59 and it works fine
@v0lume Just to be clear: you only see an issue when you upgrade?
@kneth no, it was before upgrade also.
seems something was wrong in my project, when i init new CRNA application, add realm - i don't see any errors
what happened to me is this error occurs while I stop debug js remotely, and if i enable remote debug, works fine.
What's the problem? should i continue to use realm to do the development since app could not finally release to work ?
seeing this issue as well w/ RN 0.59
Is someone able to make a clear self contained repro-case available in github?
I close the issue, and we can reopen once it can be reproduced easily.
it's very weird, everything works fine yesterday, but when I open my app and turn on'Debug JS Remotely' today, this error pops up…… I do not change any code, it just happens. but if I turn off 'Debug JS Remotely', this error will disappear.
ps. it only happened on real device with Chrome Developer Tools, so I have to use simulator, or use real device with Safari Developer Tools
update:
It works now.
Here is something I have found ,I am not quite sure if it's right ,but hope it's still useful in some ways.I think this issue is related to your local network, when you run your app on a real device and debug it with Chrome Developer Tools, the debugger will try to make a request like 'http://yourIphonIP:8083/create_session', but this request fails somehow and then this error occurs. I know it's very weird, because if you disable Chrome Developer Tools, everything is fine. but trust me this error is related to your wifi network in some way ,so the debugger can not connect to your device....😅🤦♂️
So I restart my wifi router, change ip of my mac and iPhone, and then the error disappeared.
platform: iOS
react-native: 0.60.5
realm: 2.29.2
So I restart my wifi router, change ip of my mac and iPhone, and then the error disappeared.
Wow. Yes. Super strange.
Most helpful comment
seeing this issue as well w/ RN 0.59