NetworkError: response.text is not a function
See original GitHub issueToday, 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:
- Created 6 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top GitHub Comments
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.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β
the error occurs at
.then(apolloLinkHttpCommon.parseAndCheckHttpResponse(operation))
which calls the method response.text