fetch is not defined: using minimal client inside nuxt.config.js
See original GitHub issueHey! 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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >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
@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?
@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 fromclient.fetch
is nowundefined
(https://github.com/mornir/movies-web/blob/dev/nuxt.config.js#L72). Strange 🤔 Do you see anything wrong with my query?