Build error occurred: fetch is not found globally and no fetcher passed
See original GitHub issueI was reading through the Next.js 9.4 changelog and noticed “Improved Built-in Fetch Support”. So I got rid of my isomorphic-unfetch
package but now I can’t build anymore as apollo-link-http
complains about fetch missing.
const httpLink = new HttpLink({
uri: process.env.NEXT_PUBLIC_API_URL,
});
> Build error occurred
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.
For example:
import fetch from 'node-fetch';
import { createHttpLink } from 'apollo-link-http';
In dev mode this works (fetch is not imported, using built-in one):
const httpLink = new HttpLink({
uri: process.env.NEXT_PUBLIC_API_URL,
fetch,
});
But during building I end up with the following error:
> Build error occurred
ReferenceError: fetch is not defined
at NetworkService.createApolloClient
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Using ApolloClient with node.js. "fetch is not found globally ...
I understand that the Apollo Client by default is expecting to be run in a browser context where a fetch method will be...
Read more >Node.js: '"fetch" has not been found globally and no fetcher ...
Intended outcome: I'm unable to get Apollo to run at all, starting with Getting Started from the docs. (I'm not intending to run...
Read more >Starting with Apollo Boost - A Practical Guide to GraphQL
The error occurs because the native fetch API, which is used to make requests to remote APIs on a promise basis, is only...
Read more >node – using appollo client library to fetch grapqhl data
I have a pretty basic node project in which I used graphql to expose ... Violation: "fetch" has not been found globally and...
Read more >Solved: Npm run build failure with next. - Shopify Community
I think the error is trying to say it can't find fetch on your system. Try downloading and installing node-fetch. npm install --save...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks! That helped track it down, I’ve fixed it in #12832
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.