question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetworkError: response.text is not a function

See original GitHub issue

Today, I ran an innocent little deployment, like every day, and suddenly my website was gone (thank god, staging server). All my apollo requests during SSR would return with the above mentioned NetworkError.

Here is what I had in my package.json:

    "apollo-client-preset": "^1.0.3",
    "apollo-fetch": "^0.6.0",
    "apollo-link-batch-http": "^1.0.1",
    "apollo-link-error": "^1.0.1",
    "apollo-cache-inmemory": "^1.1.1",
    "react-apollo": "^2.0.1",

After four hours of frustratingly digging through nginx & uwsgi logs and handcrafting gql requests with curl, I dawned on me that maybe my webserver and my backend are fine and somehow my node_modules environment might be messed up.

So I compared my local packages to the ones on the server via yarn list:

Here is what I had on my local machine, which works:

β”œβ”€ apollo-cache-inmemory@1.1.1
β”‚  β”œβ”€ apollo-cache@^1.0.1
β”‚  β”œβ”€ apollo-utilities@^1.0.2
β”‚  └─ graphql-anywhere@^4.0.1
β”œβ”€ apollo-cache@1.0.1
β”‚  └─ apollo-utilities@^1.0.2
β”œβ”€ apollo-client-preset@1.0.3
β”‚  β”œβ”€ apollo-cache-inmemory@^1.1.1
β”‚  β”œβ”€ apollo-client@^2.0.3
β”‚  β”œβ”€ apollo-link-http@1.1.0
β”‚  β”œβ”€ apollo-link@1.0.0
β”‚  └─ graphql-tag@^2.4.2
β”œβ”€ apollo-client@2.0.3
β”‚  β”œβ”€ @types/async@2.0.45
β”‚  β”œβ”€ @types/zen-observable@^0.5.3
β”‚  β”œβ”€ apollo-cache@^1.0.1
β”‚  β”œβ”€ apollo-link-dedup@^1.0.0
β”‚  β”œβ”€ apollo-link@^1.0.0
β”‚  β”œβ”€ apollo-utilities@^1.0.2
β”‚  β”œβ”€ symbol-observable@^1.0.2
β”‚  └─ zen-observable@^0.6.0
β”œβ”€ apollo-fetch@0.6.0
β”‚  └─ isomorphic-fetch@^2.2.1
β”œβ”€ apollo-link-batch-http@1.0.1
β”‚  β”œβ”€ apollo-fetch@^0.6.0
β”‚  β”œβ”€ apollo-link-batch@^1.0.1
β”‚  └─ graphql@^0.11.0
β”œβ”€ apollo-link-batch@1.0.1
β”œβ”€ apollo-link-dedup@1.0.2
β”œβ”€ apollo-link-error@1.0.1
β”œβ”€ apollo-link-http@1.1.0
β”œβ”€ apollo-link@1.0.0
β”‚  β”œβ”€ apollo-utilities@^0.2.0-beta.0
β”‚  β”œβ”€ apollo-utilities@0.2.0-rc.3
β”‚  └─ zen-observable@^0.6.0
β”œβ”€ apollo-utilities@1.0.2

And here is what I had on the server, which does not work:

β”œβ”€ apollo-cache-inmemory@1.1.9
β”‚  β”œβ”€ apollo-cache@^1.1.4
β”‚  β”œβ”€ apollo-utilities@^1.0.8
β”‚  └─ graphql-anywhere@^4.1.5
β”œβ”€ apollo-cache@1.1.4
β”‚  └─ apollo-utilities@^1.0.8
β”œβ”€ apollo-client-preset@1.0.8
β”‚  β”œβ”€ apollo-cache-inmemory@^1.1.7
β”‚  β”œβ”€ apollo-client@^2.2.2
β”‚  β”œβ”€ apollo-link-http@^1.3.1
β”‚  β”œβ”€ apollo-link@^1.0.6
β”‚  └─ graphql-tag@^2.4.2
β”œβ”€ apollo-client@2.2.5
β”‚  β”œβ”€ @types/async@2.0.47
β”‚  β”œβ”€ @types/zen-observable@^0.5.3
β”‚  β”œβ”€ apollo-cache@^1.1.4
β”‚  β”œβ”€ apollo-link-dedup@^1.0.0
β”‚  β”œβ”€ apollo-link@^1.0.0
β”‚  β”œβ”€ apollo-utilities@^1.0.8
β”‚  β”œβ”€ symbol-observable@^1.0.2
β”‚  └─ zen-observable@^0.7.0
β”œβ”€ apollo-fetch@0.6.0
β”‚  └─ isomorphic-fetch@^2.2.1
β”œβ”€ apollo-link-batch-http@1.1.0
β”‚  β”œβ”€ apollo-link-batch@^1.1.0
β”‚  β”œβ”€ apollo-link-http-common@^0.2.1
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link-batch@1.1.0
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link-dedup@1.0.7
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link-error@1.0.6
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link-http-common@0.2.1
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link-http@1.4.0
β”‚  β”œβ”€ apollo-link-http-common@^0.2.1
β”‚  └─ apollo-link@^1.2.0
β”œβ”€ apollo-link@1.2.0
β”‚  β”œβ”€ @types/node@^9.4.6
β”‚  β”œβ”€ @types/zen-observable@0.5.3
β”‚  β”œβ”€ apollo-utilities@^1.0.0
β”‚  β”œβ”€ zen-observable@^0.8.0
β”‚  └─ zen-observable@0.8.6
β”œβ”€ apollo-utilities@1.0.8

To fix this:

I simply pinned all the working versions in my package.json to the exact versions (I added the packages that were not in my package.json and I removed the ^ from all version numbers). Then I wiped node_modules on the server and made a new deployment.

What I don’t understand:

Both, on my MacBook and on the Ubuntu server I have:

  • node version is 9.0.4
  • yarn version is 1.3.2
  • npm version is 5.6.0

How can it be that yarn install installs packages with vastly different version numbers on both machines? This is the fist time I ended up in dependency hell like this, I never had to remove the ^ from a package.json, until now.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
TiE23commented, Apr 17, 2018

I’m sorry that my story won’t help OP but might assist those with this error experiencing issues trying to write a custom fetch for Apollo Link.

I was having the same error Network error: response.text is not a function when I was simply trying to create a custom fetch for apollo link (inspired by this article). I solved it by making a simple change to the customFetch, where the article writer was dealing with a REST api that returned JSON in the response, whereas GraphQL returns text.

const customFetch = (uri, options) => {
  const initialRequest = fetch(uri, options);

  return initialRequest.then(response => (
    response.text()
  )).then((text) => {
    // ... If there is an error do something special HERE
    // ... Just passing things through as "OK"
    const result = {};
    result.ok = true;
    result.json = () => new Promise((resolve, reject) => {
      resolve(text);
    });
    return result;
  });
};

const httpLink = createHttpLink({
  uri: "http://localhost:4000",
  fetch: customFetch,
});
3reactions
jhd124commented, May 19, 2018

look at this: https://developer.mozilla.org/en-US/docs/Web/API/Body/text. the response of fetcher should own a text method. In the module β€œapollo-link-http”

return new apolloLink.Observable(function (observer) {
              console.log('options', options)
                fetcher(chosenURI, options)
                    .then(function (response) {
                      console.log('before', response)
                    operation.setContext({ response: response });
                    console.log('after', operation)
                    return response;
                })
                    .then(apolloLinkHttpCommon.parseAndCheckHttpResponse(operation))
                    .then(function (result) {
                      console.log('result',result)
                    // we have data and can send it to back up the link chain
                    observer.next(result);
                    observer.complete();
                    return result;
                })
...

the error occurs at .then(apolloLinkHttpCommon.parseAndCheckHttpResponse(operation)) which calls the method response.text

Read more comments on GitHub >

github_iconTop Results From Across the Web

why do I got Uncaught TypeError: response.text is not a ...
I've tried to use "await fetch" but I got this error: Uncaught SyntaxError: await is only valid in async function. – Andrei. May...
Read more >
KB-2112 "response.text is not a function" error thrown on front ...
Cause. There is a communication issue between the end user's browser client and the Appian server(s). Action. Troubleshoot the integrity and performance ofΒ ......
Read more >
NetworkError: response.text is not a function - Bountysource
Today, I ran an innocent little deployment, like every day, and suddenly my website was gone (thank god, staging server).
Read more >
Handling operation errors - Apollo GraphQL Docs
These are errors encountered while attempting to communicate with your GraphQL server, usually resulting in a 4xx or 5xx response status code (and...
Read more >
Fix JavaScript errors that are reported in the Console
A network error that starts with GET HTTP method followed by a URI. An Uncaught (in promise) TypeError: data.forEach is not a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found