TypeError: createClient is not a function in Sanity TypeScript code
Based on the community discussion you've linked to, this error typically occurs due to a version compatibility issue between @sanity/client and your Sanity Studio version.
The Problem:
You're using @sanity/client v5.2.2 with @sanity/core v2.35.6 (which indicates you're on Sanity Studio v2). The issue is that @sanity/client v5+ no longer supports ES5, which can cause problems when working with a v2 Studio.
The Solution:
You have two options:
Option 1: Downgrade to @sanity/client v4 (Quick Fix)
- Delete your
node_modulesfolder and lock file - Edit your
package.jsonand change the dependency to:"@sanity/client": "^4" - Run
npm install(oryarn)
Option 2: Upgrade to Sanity Studio v3 (Recommended)
This is the better long-term solution. Sanity Studio v3 is the current version and works seamlessly with @sanity/client v5+. You can follow the migration guide to upgrade your Studio.
Additional Notes:
- Your import syntax is correct for v5+:
import { createClient } from '@sanity/client' - If you get an error with
import {createClient, type ClientConfig}, you can use separate imports instead:import { createClient } from '@sanity/client' import type { ClientConfig } from '@sanity/client' - Update your
apiVersionto a more recent date (like'2024-01-01'or the current date in YYYY-MM-DD format)
The community members who helped solve this were able to identify the version mismatch as the root cause, and upgrading to Studio v3 resolved the issue completely.
Show original thread46 replies
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.