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

fetch is undefined in React Native #26

Closed
tgamauf opened this issue Oct 21, 2018 · 4 comments
Closed

fetch is undefined in React Native #26

tgamauf opened this issue Oct 21, 2018 · 4 comments

Comments

@tgamauf
Copy link

tgamauf commented Oct 21, 2018

I've written an API wrapper that uses cross-fetch to make it compatible with Browsers, Node and React Native. Now, if I test it with Node it works perfectly, but if I use the wrapper in React Native if fails with the following error: TypeError: undefined is not a function (evaluating 'cross_fetch_1.default(url, init)'). If I print the type of cross_fetch_1 I get:

{ [Function]
   polyfill: true,
  Response: { [Function: Response] error: [Function], redirect: [Function] },
  Request: [Function: Request],
  Headers: [Function: Headers] }

and "undefined" for either cross_fetch_1.default or cross_fetch_1.fetch.

The library was developed in Typescript, so the cross_fetch_1 variable is created by the TS compiler. You can find the Typescript code here https://github.com/tgamauf/onetimesecret-api/blob/1b8edff66bde11807c8ff7d29030b4d3e6661277/lib/request.ts#L150 and the compiled JS here https://github.com/tgamauf/onetimesecret-api/blob/1b8edff66bde11807c8ff7d29030b4d3e6661277/lib/request.js#L179.

As far as I can tell I am using the module as it is supposed to be used. What could cause this?

@mattmccutchen
Copy link
Contributor

Also reported here. cross-fetch should probably add a default export to browser-ponyfill.js, just as node-ponyfill.js has.

mattmccutchen added a commit to mattmccutchen/cross-fetch that referenced this issue Oct 21, 2018
@tgamauf
Copy link
Author

tgamauf commented Oct 21, 2018

As Matt noted in the Stackoverflow question, activating esModuleInterop in the Typescript compiler is a workaround. I agree, this should be fixed as it isn't really expected behavior.

lquixada pushed a commit that referenced this issue Oct 25, 2018
@sondremare
Copy link

@lquixada Do you have an estimate of when this will be released?

@lquixada
Copy link
Owner

@sondremare hopefully this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants