lucasfeliciano / fetch-everywhere

WHATWG Fetch API, for ALL JavaScript environments!
MIT License
53 stars 13 forks source link

React Native: undefined is not an object (evaluating ‘r.fetch.bind’) imported from null #9

Open siddharthlatest opened 6 years ago

siddharthlatest commented 6 years ago

On the lines of #8, we're seeing an issue with a library we are building @appbaseio/reactivesearch-native that has a dependency that uses fetch-everywhere.

Exact error:

Device: (1069:6932) Failed to install module ‘@appbaseio/reactivesearch-native’: undefined is not an object (evaluating ‘r.fetch.bind’) imported from null

Do you have any pointers on how we could resolve it?

This is an online environment where the error can be seen: https://snack.expo.io/@siddharthlatest/reactivesearch-snack

siddharthlatest commented 6 years ago

I think this is the likely root cause: https://github.com/lucasfeliciano/fetch-everywhere/blob/master/fetch-npm-browserify.js#L6

On react-native environment, L7 somehow evals to this.fetch.bind(this) which causes the error. See this snack snippet that demonstrates this - https://snack.expo.io/B1gJ6nx8G.

Error log on this snippet:

screen shot 2018-02-01 at 9 45 47 pm

jhubbardsf commented 5 years ago

The solution to this is posted here. I found it after a lot of searching. I'll fix it and put in the pull request in a few. Until it's merged you can monkey patch it in your app yourself or use my fork. Although I do realize this is a very old issue.