matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

Error: Can't find variable: self #125

Closed Connorelsea closed 3 years ago

Connorelsea commented 7 years ago

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

karimmorta commented 7 years ago

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);
gardner commented 7 years ago

A place to start: https://github.com/apollographql/apollo-client/compare/6bd8786f88d575b0f45a27a02ccc9ce8ceb38ab2...aae04f76913769836308b1eb87ecab6e0efc4784

CaryLandholt commented 6 years ago

This worked for me (https://github.com/apollographql/apollo-link/issues/75#issuecomment-333328069)

lquixada commented 6 years ago

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.

Taylor123 commented 6 years ago

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

cobra0901 commented 5 years ago

npm add whatwg-fetch@2.0.4 --save