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.

fetch is not defined: using minimal client inside nuxt.config.js

See original GitHub issue

Hey! It’s me again 😁

I’m using the minimal client inside nuxt.config.js in order to fetch all the routes at build time. I followed the approach you described here: https://github.com/nuxt-community/sanity-module/issues/3

// for minimal client
import { createClient } from '@nuxtjs/sanity'

const client = createClient({
  projectId: 'xxxxxxx',
  useCdn: false,
})

But when calling client.fetch, I get the error fetch is not defined. At first, I thought it was the property fetch on the client object that was undefined, but it’s actually the Fetch API that isn’t defined.

I know that, in this case, the runtime is Node, but I thought that the minimal client was isomorphic, because it works fine inside ayncData(). Also, I think that this used to work in previous versions of the module.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
danielroecommented, Feb 1, 2021

@mornir Agreed - I think a very sensible approach. Using it in Nuxt config to generate routes shouldn’t add to your bundle size but why add another dependency if you don’t need to?

1reaction
mornircommented, Feb 1, 2021

@danielroe Thanks for the quick reply! So I did it this way: https://github.com/mornir/movies-web/blob/dev/nuxt.config.js#L3

Now I no longer get the error fetch is undefined, but the results from client.fetch is now undefined (https://github.com/mornir/movies-web/blob/dev/nuxt.config.js#L72). Strange 🤔 Do you see anything wrong with my query?

Read more comments on GitHub >

github_iconTop Results From Across the Web

fetch is not defined: using minimal client inside nuxt.config.js #67
Hey! It's me again I'm using the minimal client inside nuxt.config.js in order to fetch all the routes at build time.
Read more >
ReferenceError: fetch is not defined - javascript - Stack Overflow
This is the function I am doing, it is responsible for recovering information from a specific movie database.
Read more >
Data Fetching - Nuxt
In Nuxt we have 2 ways of getting data from an API. We can use the fetch method or the asyncData method. Nuxt...
Read more >
Cannot fetch data - Developing with Prismic
My nuxt.config.js matches the "crash course" but I can't seem to get data ... I get " Cannot read properties of undefined (reading...
Read more >
API: The fetch Method - NuxtJS
Nuxt.js v2.12 introduces a new hook called fetch in any of your Vue components. ... fetchDelay : Integer (default: 200 ), set the...
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