
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe error you're seeing is a CORS (Cross-Origin Resource Sharing) issue, not a problem with the Sanity JavaScript SDK itself. The SDK works great with Next.js, but when you make Sanity API calls from the browser (like in componentDidMount), you need to configure CORS origins.
You need to whitelist your Next.js application's domain in your Sanity project settings:
http://localhost:3000 (or whatever port you're using)https://yourdomain.comYou can add multiple origins (one for localhost, one for staging, one for production, etc.).
If you prefer a server-side approach without using getServerSideProps, you can create a Next.js API route that handles the Sanity query server-side, then fetch from that endpoint in your component. This way you don't need to configure CORS at all since the Sanity client runs on your server.
The CORS configuration documentation is available at the Sanity CORS docs, and you can also manage CORS origins via the Sanity CLI with sanity cors add if you prefer the command line approach.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store