TypeError: createClient is not a function in Sanity TypeScript code

46 replies
Last updated: Nov 29, 2025
Hello All... new to Sanity and Typescript so there is probably an obvious answer, but I'm getting this error: TypeError: Object(...) is not a function using this codeimport { createClient } from '
user E
/client'import type { ClientConfig } from '
user E
/client';
export async function *getIgnoredHandles*() {
const config:
ClientConfig = { projectId: 'project id',
dataset: 'production',
useCdn: false,
// set to
true
to fetch from edge cache
apiVersion: '2023-03-03',
// use current date (YYYY-MM-DD) to target the latest API version }

const client = *createClient*(config);
const response = await client.*fetch*('*[_type == "ignoredHandles"]');

const ignoredHandles: *IgnoredHandle*[] = response.*map*((handle: any) => ({
id: handle.id,
handle: handle.handle,
datereview: handle.datereview
}));

return ignoredHandles;

}

export interface
IgnoredHandle { id: string;
handle: string;
datereview: string;
}
AI Update

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)

  1. Delete your node_modules folder and lock file
  2. Edit your package.json and change the dependency to:
    "@sanity/client": "^4"
  3. Run npm install (or yarn)

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 apiVersion to 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 thread
46 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.

Was this answer helpful?