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

Importing Realm returns the error "Undefined is not a constructor (evaluating 'new XMLHttpRequest')" #1788

Closed
joshdhenry opened this issue May 10, 2018 · 31 comments

Comments

@joshdhenry
Copy link

joshdhenry commented May 10, 2018

Goals

Import Realm into a React Native project.

Expected Results

I should be able to import Realm and run the project in iOS with crashing.

Actual Results

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

Steps to Reproduce

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';

Version of Realm and Tooling

  • Realm JS SDK Version: 2.4.1
  • Node or React Native: RN v0.46.2
  • Client OS & Version: Mac OSX 10.13.4
  • Which debugger for React Native: Xcode v9.3
@kneth
Copy link
Contributor

kneth commented May 16, 2018

Maybe I misinterpret:

crashes in debug mode if not using Chrome Debugger

but you can only debug React Native apps using Chrome.

@joshdhenry
Copy link
Author

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"

@arshbot
Copy link

arshbot commented Jun 12, 2018

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

@kneth
Copy link
Contributor

kneth commented Jun 13, 2018

#1732 is a similar issue with some suggestion on how to solve it.

@mohannad-mamo
Copy link

@arshbot were you able to overcome this issue?

@woodpav
Copy link

woodpav commented Sep 5, 2018

It works when I am remote debugging (:8081).

It does not work when not remote debugging.

@mohannad-mamo
Copy link

@woodpav what about the production build?

@woodpav
Copy link

woodpav commented Sep 6, 2018

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.

@arshbot
Copy link

arshbot commented Sep 6, 2018

@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

@mohannad-mamo
Copy link

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.

@Michaelvilleneuve
Copy link

Seing this too, should be reopened

@bmunkholm bmunkholm reopened this Sep 11, 2018
@bmunkholm
Copy link
Contributor

@Michaelvilleneuve @sheva007 @arshbot Any suggestions on how to reproduce this?

@Michaelvilleneuve
Copy link

Michaelvilleneuve commented Sep 11, 2018

Honestly I have no idea. It just started happening and since then I can’t remove that error unless I activate chrome remote debugging

@mohannad-mamo
Copy link

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"
}

@Michaelvilleneuve
Copy link

Michaelvilleneuve commented Sep 11, 2018

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

@Michaelvilleneuve
Copy link

By the way, something similar happens on Android. This message is iOS only but here is the error for both platforms :

  • ios crash :

undefined is not a constructor (evaluating 'new XMLHttpRequest()')
makeRequest - rpc.js:204:22

  • android crash :

Can't find variable : Symbol
<unknown> - constants.js:30:24

@JamesZhange
Copy link

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

@joshdhenry
Copy link
Author

joshdhenry commented Sep 29, 2018

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

@tomershohet
Copy link

I have the same issue too, any updates? (React native 0.54.5, Realm v2.17.0, Android)

@EnettyTech
Copy link

I still have the same error, did anyone solve it?
"realm":"2.24.0",
"react-native":0.55.3"

@v0lume
Copy link

v0lume commented Mar 12, 2019

also facing this error, does anybody have any solutions?

@kneth
Copy link
Contributor

kneth commented Mar 12, 2019

We have just released v2.25.0. Please try to upgrade.

@v0lume
Copy link

v0lume commented Mar 14, 2019

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

@kneth
Copy link
Contributor

kneth commented Mar 14, 2019

@v0lume Just to be clear: you only see an issue when you upgrade?

@v0lume
Copy link

v0lume commented Mar 14, 2019

@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

@Michael4691
Copy link

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 ?

@barbatus
Copy link

seeing this issue as well w/ RN 0.59

@bmunkholm
Copy link
Contributor

Is someone able to make a clear self contained repro-case available in github?

@kneth
Copy link
Contributor

kneth commented Aug 14, 2019

I close the issue, and we can reopen once it can be reproduced easily.

@kneth kneth closed this as completed Aug 14, 2019
@YaoHuiJi
Copy link

YaoHuiJi commented Oct 12, 2019

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

@kneth
Copy link
Contributor

kneth commented Oct 15, 2019

So I restart my wifi router, change ip of my mac and iPhone, and then the error disappeared.

Wow. Yes. Super strange.

@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.
Projects
None yet
Development

No branches or pull requests