Discussion about configuring Sanity and Nuxt, using the nuxt-sanity module, and resolving issues with fetching data.
Great question! You're actually looking at two different approaches to integrating Sanity with Nuxt, and understanding the difference will help you decide which path is best for your project.
What you have now (@sanity/client): You're using the core Sanity JavaScript client directly. This works perfectly fine and gives you full control over how you set up and use the client.
What nuxt-sanity offers: The nuxt-sanity module is a Nuxt-specific wrapper that provides:
- Auto-configuration through
nuxt.config.ts - Nuxt composables like
useSanityQuery()for fetching data - Better integration with Nuxt's SSR/SSG features
- Image URL helper integration
- Simpler setup for visual editing features
Will they conflict? They won't necessarily conflict, but you'd be running two separate clients which is redundant. Here's what I'd recommend:
If your current setup with @sanity/client is working and you're comfortable with it, there's no urgent need to switch. However, if you want the benefits of Nuxt-native composables and cleaner integration, switching to nuxt-sanity would be worthwhile.
Migration approach: Instead of having both, I'd suggest replacing your current setup:
- Install:
npx nuxi@latest module add sanity - Configure in
nuxt.config.ts:
export default defineNuxtConfig({
modules: ["@nuxtjs/sanity"],
sanity: {
projectId: 'your-project-id',
dataset: 'production',
},
})- Replace your manual
sanityClientimports with theuseSanityQuery()composable in your components - Remove your old
sanity.jsfile and@sanity/clientdependency once everything's migrated
The nuxt-sanity module is essentially a convenience layer over the same @sanity/client you're already using, so you're not losing any functionality—just gaining some Nuxt-specific ergonomics. The Nuxt.js quickstart guide has detailed examples of using the module if you decide to make the switch!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.