tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
615 stars 112 forks source link

http module breaks #71

Closed nomoreboredom closed 4 years ago

nomoreboredom commented 6 years ago

hi @mvayngrib

Currently i am experiencing a problem. Normally nodeifying was working pretty good, but however after the latest web3-core update, (web3.js 1.0.0-beta.35, see breaking change: The HTTP provider now accepts an options object, instead of timeout and headers parameters:) this line fails on xhr2-cookies:

if (this.withCredentials && (response.headers['set-cookie'] || response.headers['set-cookie2'])) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

and throws Cannot read property 'set-cookie' of undefined.

If I do comment out response.headers['set-cookie'] parts from the node module xhr2-cookies, i do get a ssl error when i try to connect to ethereum rpc node. So this cookie is normally using browser cache I think, whereas we dont have a substitude for that from rn-nodeify. Is this assumption correct, what do you think?

Cheers

mvayngrib commented 6 years ago

@nomoreboredom thanks for reporting this! Could you poke around in https://github.com/tradle/react-native-http/blob/master/lib/response.js and see why response.headers isn't being defined in your case? (If that's where the response object is coming from. If not, where is it being created?)

nomoreboredom commented 6 years ago

My app is throwing on this line actually, from xhr2-cookies, xml-http-request.js file line:

if (this.withCredentials && (response.headers['set-cookie'] || response.headers['set-cookie2'])) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

and if I add this check, it stops to throw but I can not build the connection I am supposed to build.

if (this.withCredentials && ((response.headers && response.headers['set-cookie']) || (response.headers && response.headers['set-cookie2']))) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

Hmm actually it may be a web3 bug, as I just noticed this issue: https://github.com/ethereum/web3.js/issues/1802.

Thanks anyway, will follow that issue and reopen this if it still persists :)

nomoreboredom commented 6 years ago

So I traced down the issue to this change from web3 lib:

var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line

It was before just using XMLHttpRequest, whereas it now uses a lib for managing cookies. But as the cookie storage is not per default available for react native, do you think I need to nodeify this using this a package like this, or is it perhaps already done via react-native-http? https://github.com/joeferraro/react-native-cookies

Thanks!

mvayngrib commented 6 years ago

@nomoreboredom no idea yet :) Can you check why the response is being created without a headers field? That doesn't sound right. And is the response object being created from inside react-native-http or elsewhere?

0es commented 6 years ago

Same issue

fomenyesu commented 6 years ago

web3 issue . downgrade to v1.0.0-beta.33 solved my problem.

john-osullivan commented 5 years ago

Running into the same issue, also trying to make web3 work. In my case, Cannot read property 'node' of undefined is throwing out of XMLHttpRequest. Going to see if downgrading fixes things.

EDIT: Maybe, although not quite. I do get a different error, but now it says that it can't connect. Currently trying to get an HTTPProvider to talk to local Ganache from the Android emulator, no dice. Could be related to something else, though.

mvayngrib commented 4 years ago

closing as web3 issue. If anyone wants to poke around with improving compatibility, happy to reopen