schema.getTypeNames is not a function error in Sanity Studio

21 replies
Last updated: Nov 29, 2025
Howdy everyone! When going through the Live Preview with Next.js and Sanity.io: A Complete Guide I am getting an unhandled error in the browser at 3333 despite a successful build. What’s odd is that this was working until reaching the section Setting up the Production Preview . Devtools:
Failed to load defined templates, falling back to defaults:
Console:
TypeError: schema.getTypeNames is not a function
    at Object.defaults (/static/js/app.bundle.js:103002:17)
    at getDefaultTemplates (/static/js/app.bundle.js:179904:44)
    at getTemplates (/static/js/app.bundle.js:179926:12)
    at Object.defaultInitialValueTemplateItems (/static/js/app.bundle.js:108729:59)
    at getNewDocumentOptions (/static/js/app.bundle.js:208056:93)
    at /static/js/app.bundle.js:208028:14
    at Object. (/static/js/app.bundle.js:289588:62)
    at __webpack_require__ (/static/js/vendor.bundle.js:713:30)
    at fn (/static/js/vendor.bundle.js:118:20)
    at Object. (/static/js/app.bundle.js:289528:29)
My schema is identical to the example. The /web front end builds perfectly, correctly pulling content from Sanity. There are no ESLint errors thanks to the
"eslint.workingDirectories": ["./web", "./studio"]
in
/.vscode/settings.json
and node_modules has been replaced already. Any ideas how I can track this down?
AI Update

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 createSchema export)
  • 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 thread
21 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?