apollographql / apollo-link

:link: Interface for fetching and modifying control flow of GraphQL requests
https://www.apollographql.com/docs/link/
MIT License
1.44k stars 344 forks source link

Invariant Violation Issue #1025

Open shridharbhande-tudip opened 5 years ago

shridharbhande-tudip commented 5 years ago

import fetch from 'node-fetch'; import { createHttpLink } from 'apollo-link-http';

const link = createHttpLink({ uri: '/graphql', fetch: fetch }); at new InvariantError (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/node_modules/apollo-link-http-common/node_modules/ts-invariant/lib/invariant.js:16:28) at Object.exports.checkFetcher (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/node_modules/apollo-link-http-common/lib/index.js:65:15) at exports.createHttpLink (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/nodemodules/apollo-link-http/lib/httpLink.js:9:31) at Module.1TCz (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/app.js:1:3209) at r (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/app.js:1:225) at Object.0 (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/app.js:1:1804) at r (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/app.js:1:225) at /home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/app.js:1:1059 at Object. (/home/lt-113/Documents/ShridharProject/Shopify-FENode/shopify/.next/server/static/FCCYkOEpZlp1z4k4uL7i/pages/_app.js:1:1068) at Module._compile (module.js:569:30) framesToPop: 1, name: 'Invariant Violation' } { Invariant Violation: fetch is not found globally and no fetcher passed, to fix pass a fetch for your environment like https://www.npmjs.com/package/node-fetch.

Why this error is occuring on my local machine?

helfer commented 5 years ago

Most likely your import statement isn't doing what you think it's doing. What do you get when you console.log fetch right after importing it?

K-Kit commented 5 years ago

https://github.com/matthew-andrews/isomorphic-fetch this fixed for me

import and add it at the end of your client constructor args