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:
Here is the stack trace:
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);
A place to start: apollographql/apollo-client@6bd8786...aae04f7
This worked for me (apollographql/apollo-link#75 (comment))
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