Apollo - React (Typescript) Invariant Error when building production build Apollo - React (Typescript) Invariant Error when building production build typescript typescript

Apollo - React (Typescript) Invariant Error when building production build


I'm a newbie at this. After hours of looking I finally tracked down the error in the file. On closer inspection, when the environment is production (process.env.NODE_ENV === "production"), then the error is not detailed. So I looked at what the error would be if the environment was something else, and changed the file to output this to the console. What I got back was:

fetch is not found globally and no fetcher passed, to fix pass a fetch foryour environment like https://www.npmjs.com/package/node-fetch.For example:import fetch from 'node-fetch';import { createHttpLink } from 'apollo-link-http';const link = createHttpLink({ uri: '/graphql', fetch: fetch });

I added fetch to my code, and it built a production version with no errors.

I don't understand why this error was not thrown with the dev environment, but I guess it's something to do with the lazy loading.

Problem fixed.