question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build error occurred: fetch is not found globally and no fetcher passed

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
timneutkenscommented, May 13, 2020

Thanks! That helped track it down, I’ve fixed it in #12832

0reactions
balazsorban44commented, Jan 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found