matthew-andrews/isomorphic-fetch

Error: Can't find variable: self

Connorelsea opened this issue ยท 6 comments

Hello.

I am using redux-api-middleware which is using version 2.2.1 of isomorphic-fetch. I am experiencing an error where self is undefined in React Native, which is a problem with this version of isomorphic-fetch. Most issues I have seen regarding this issue have been closed, but I feel that this is a fairly common issue and I have not been able to find a good solution. I'd love to work together, with a maintainer or anyone else having this problem, to solve it.

Thank you for reading and for your work on this library.

The error seems to be coming from this file:

image

Here is the stack trace:

image

Here is a fix I use :

require('whatwg-fetch');
// module.exports = self.fetch.bind(self);
var globalObject = typeof self === "undefined" ? global : self;
module.exports = globalObject.fetch.bind(globalObject);

For all those seeking for an isomorphic-fetch with React Native support alternative, see cross-fetch. It is updated and also brings optional polyfill.

graphql-request and VulcanJS are already using it.

Are there any plans to make an update to fix this?

npm add whatwg-fetch@2.0.4 --save