schema.getTypeNames is not a function error in Sanity Studio
I found the exact issue you're experiencing! This is a common problem when setting up the production preview feature in Sanity Studio v2 (the older version using sanity.json).
The error schema.getTypeNames is not a function happens because your sanity.json file has incorrectly combined two separate "parts" into one. Looking at your configuration:
"parts": [
{
"name": "part:@sanity/base/schema",
"implements": "part:@sanity/production-preview/resolve-production-url",
"path": "./resolve-production-url.js"
}
]The problem is that you're telling Sanity that your schema file is located at ./resolve-production-url.js, which is actually your production URL resolver. This causes the schema system to fail because it can't find the proper schema definition.
The Solution
You need to separate these into two distinct parts in your sanity.json:
"parts": [
{
"name": "part:@sanity/base/schema",
"path": "./schemas/schema.js"
},
{
"name": "part:@sanity/desk-tool/structure",
"path": "./deskStructure.js"
},
{
"implements": "part:@sanity/production-preview/resolve-production-url",
"path": "./resolve-production-url.js"
}
]Key points:
- The first entry should point to your actual schema file (wherever you have your
createSchemaexport) - The production preview resolver uses
"implements"instead of"name" - Each part needs its own separate object in the array
Make sure the path in the first entry ("./schemas/schema.js" or similar) matches where your actual schema file is located - the one with the createSchema function you shared earlier.
After making this change, restart your Studio dev server and the error should be resolved!
Note: If you're starting a new project today, I'd recommend using Sanity Studio v3, which has moved away from the sanity.json parts system to a more straightforward configuration approach using sanity.config.ts.
Show original thread21 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.