Closed lunchboxer closed 5 years ago
I was able to fix this by globally defining fetch
for the server:
npm i --save node-fetch
(already a dependency of sapper, but good to have it explicit`src/server.js
import fetch from 'node-fetch';
global.fetch = fetch;
import fetch from 'node-fetch'; global.fetch = fetch;
I don't know why this doesn't work for me, so I tried to put the fetch on the fetch parameter of apollo-boost
import fetch from 'node-fetch' const client = new ApolloClient({ uri: URL, fetch })
I was able to fix this by globally defining
fetch
for the server:
npm i --save node-fetch
(already a dependency of sapper, but good to have it explicit`- Add the following to
src/server.js
import fetch from 'node-fetch'; global.fetch = fetch;
This doesn't work!
I was able to fix this by globally defining
fetch
for the server:
npm i --save node-fetch
(already a dependency of sapper, but good to have it explicit`- Add the following to
src/server.js
import fetch from 'node-fetch'; global.fetch = fetch;
This doesn't work!
const httpLink = new HttpLink({
uri: `https:${API}/graphql`,
fetch: !process.browser && require('node-fetch') || fetch,
credentials: 'include',
// credentials: 'same-origin',
})
With Sapper the ssr gets tripped up by apolloClient which insists that it be passed a fetch function, since node doesn't have one. They recommend node-fetch, but rollup gets totally mixed up when it comes to node-fetch. How do I get around this?
Starting with the sapper v3 rollup template I cleared the routes and added svelte-apollo in a manner similar to the sapper section of the readme.
install svelte-apollo apollo-boost and graphql then clear index.html and replace it with:
the error looks like this: