Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Critical error when simply importing the library #75

Closed
Nickersoft opened this issue Sep 17, 2017 · 9 comments
Closed

Critical error when simply importing the library #75

Nickersoft opened this issue Sep 17, 2017 · 9 comments

Comments

@Nickersoft
Copy link

Intended outcome:
I'm just trying to import the following into my React Native app, as seen in the docs:

import {execute, HttpLink} from 'apollo-link';

Actual outcome:
However, upon simply injecting this line, my React Native app immediately errors:

<Error>: Can't find variable: self
<Critical>: Unhandled JS Exception: Can't find variable: self
<Error>: undefined is not an object (evaluating 'require(487      ).default')
<Critical>: Unhandled JS Exception: undefined is not an object (evaluating 'require(487      ).default')
<Error>: Requiring module "myapp/src/config/Apollo.js", which threw an exception: Error: Requiring module "917", which threw an exception: ReferenceError: Can't find variable: self
<Error>: Requiring module "917", which threw an exception: ReferenceError: Can't find variable: self

How to reproduce the issue:
All I did was attempt to import the library, so I imagine that's all that is required.

Any insight as to what might be wrong? Some more info:

apollo-link version: 0.5.4
react-apollo version: 1.4.15
react-native version: 0.48.1
react version: 16.0.0-alpha.12

@affablebloke
Copy link

affablebloke commented Sep 20, 2017

This library depends on apollo-fetch and apollo-fetch depends on isomorphic-fetch.

isomorphic-fetch has issues with React Native...

@Nickersoft
Copy link
Author

Oh hm... Guess I'll just have to wait out a fix then. Thanks for the insight!

@affablebloke
Copy link

@Nickersoft if you don't feel like waiting, or rolling your own ApolloLink, do this...
matthew-andrews/isomorphic-fetch#125 (comment)

@CaryLandholt
Copy link

@affablebloke are you suggesting forking isomorphic-fetch?

if not, where do you place the following fix?

image

Cheers!

@affablebloke
Copy link

@CaryLandholt

It depends on your project's setup. I have placed this line at the top of App.js. Or you could place it at the top of both index.android.js and index.ios.js.

// Fixes isomorphic-fetch
GLOBAL.self = GLOBAL;

Doing this before any imports of isomorphic-fetch will monkey patch the GLOBAL object for React Native.

@CaryLandholt
Copy link

@affablebloke worked perfectly - thanks!

@jbaxleyiii
Copy link
Contributor

The apollo-link-http no longer uses global fetch so this shouldn't be a problem! I'll be updating the batching fetch in the new few weeks to do the same!

@dozoisch
Copy link
Contributor

@jbaxleyiii would be really nice to have batch use the global fetch too!

@michaelknoch
Copy link

is batch-http now using global fetch? still facing this error with batch-http@1.0.0
@jbaxleyiii

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

No branches or pull requests

6 participants