I have developed an API wrapper that utilizes fetch to carry out the API requests. To ensure compatibility with Browsers, Node, and React Native, I incorporate cross-fetch. When testing the wrapper in Node, everything works fine. However, when using it in React Native, it fails with the error message:
TypeError: undefined is not a function (evaluating 'cross_fetch_1.default(url, init)')
. Upon checking the type of cross_fetch_1, I observed:
{ [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 written in Typescript, so the cross_fetch_1 variable is generated by the TS compiler. The Typescript code can be found here https://github.com/tgamauf/onetimesecret-api/blob/1b8edff66bde11807c8ff7d29030b4d3e6661277/lib/request.ts#L150, and the compiled JS version here https://github.com/tgamauf/onetimesecret-api/blob/1b8edff66bde11807c8ff7d29030b4d3e6661277/lib/request.js#L179.
Despite following the correct usage of the module, I am encountering this issue. What could be causing it?
I have also raised a github issue regarding this problem here: https://github.com/lquixada/cross-fetch/issues/26