-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Missing Stream API causes problems in ReactNative #2840
Comments
Maybe @hugomrdias could polyfill the stream API in Though I think longer term we are switching this module over to use |
This should do the trick https://www.npmjs.com/package/web-streams-polyfill |
Question why are you getting the browser version of iso-stream-http? Are you bundling? You should be getting the node version |
Thanks for the quick replies! Using
I've tried to polyfill Symbol, but it's not been effective. I just tried the web-streams-polyfil, but still have the same issue. Main problem is that body isn't defined in the response. This causes this line to throw an error. I'm not sure why I'm getting the browser version. Is there any way I can force it to use the node one? Is that even available in RN? Edit: |
Polyfill with this https://github.com/github/fetch/blob/master/fetch.js |
Plus this for iterator in your index.js |
Thanks @hugomrdias I did try adding the symbol polyfill before with no improvements. Double checked now and got the same result in The |
Body needs to be defined now with that polyfill what's the error |
Maybe I'm doing something wrong then. I'm adding this to index.js: global.fetch = require('whatwg-fetch').fetch But i still get an error saying the same thing:
Edit: I don't see body being defined anywhere in https://github.com/github/fetch/blob/master/fetch.js |
@hugomrdias What do you make of that latest error @oed was running into? Thanks! |
@achingbrain Can you speculate on the timeline for a move to |
Have you tried the latest version? |
@hugomrdias @alanshaw I'll give it a try today! Was there anything in particular that changed in the latest version that you had in mind that might address this? |
🙄 my apologies I just dug in deeper and unless RN has fixed their fetch impl I think this will still be a problem. |
@alanshaw Noted, that's what I thought. Thanks for looking into this! |
@pcowgill are you able test if using this https://www.npmjs.com/package/react-native-v8 instead of the default jsc help with this ? |
Update: @achingbrain I see that But getting a fetch API working applies still, since |
@hugomrdias Sure, I'll give that a try. Thanks. |
@hugomrdias FYI this issue mentioned above:
is still a problem with the latest version of this package and the latest version of React Native. I'm pretty sure the solution isn't polyfilling The issue seems to be getting the The problem steps from the use of the it packages like is done here in the js-ipfs-http-client codebase for most of the ipfs.{insertmethodhere} calls. The The |
I am able to reproduce the undefined error above with a minimal snippet not using the
|
So the problem is async iterators? I don't understand the roll-up Babel issue why can't you transpile the iterators in your project? |
@hugomrdias It seems that way, yes. Transpiling the iterators in our project is definitely an option worth considering, but if a goal for this library is wide adoption, including a build script in this repo and publishing prebuilt vanilla js code to npm that can be used in a project with any Babel config seems ideal for making it approachable for developers with minimal setup friction. That's what most libraries do these days, right? |
http-client works in react-native with these instruction react-native
Add To connect to a ipfs daemon using localhost:5001
or change ipfs config API to 0.0.0.0 connect using local IP
Test code
|
@hugomrdias Thanks for looking into this! Have you tried with any other IPFS methods, like |
The If you modify the
you should be able to reproduce the async iterator error message.
|
@hugomrdias and I chatted about trying to import the browser bundle for const ipfsClient = require("ipfs-http-client/dist/index.js"); and that does appear to get past the async iterator error! The error message with the browser bundle is
...which is different than the one before. That new error occurs because the fetch available in a React Native env and the GitHub pollyfill for fetch both don't implement I added a suggestion about error handling for the case when body is undefined in another issue here. So if we can get fetch-readablestream working with a suitable polyfill for |
Thanks for transferring this issue. I think that's a great way to handle open issues now that most of the packages are moving into the For those following this issue for the state of using |
Closing this one in favor of #2813 Thanks you all 🙏 |
I'm trying to get the ipfs-http-client running in react-native, but ran into an issue I wasn't able to easily solve. The problem stems from that the iso-stream-http uses the fetch stream API, which seems to be available in browsers, but is not in the RN implementation of fetch.
The problem is outlined in this stackoverflow post. It also seems that the RN team is not very interested in adding support for this.
I've tried various fetch replacements, but none of the seem to support the stream api. Now I'm wondering what the next step could be? Is there some other way around this perhaps? Happy to hear suggestions 🙂
The text was updated successfully, but these errors were encountered: