Issue with parent/child taxonomy template in Sanity Studio v3
I can see the exact issue you're experiencing! Looking at the official Sanity Parent/Child Taxonomy guide and community discussions about this same error, the most common cause is actually a configuration placement issue rather than a problem with the S.initialValueTemplateItem() syntax itself.
The error "template id (templateId) is required for initial value template item nodes" typically occurs when the initial value template isn't properly registered or accessible when the Structure Builder runs.
The most likely culprit: Your templates configuration is placed outside the schema object in sanity.config.ts.
Here's what your config should look like:
// ./sanity.config.ts
import {defineConfig} from 'sanity'
import {schemaTypes} from './schemas'
export default defineConfig({
// ...all other settings
schema: {
// All your schema types
types: schemaTypes,
// ⚠️ Make sure 'templates' is INSIDE the schema object
templates: (prev) => {
const categoryChild = {
id: 'category-child',
title: 'Category: Child',
schemaType: 'category',
parameters: [{name: `parentId`, title: `Parent ID`, type: `string`}],
// This value will be passed-in from desk structure
value: ({parentId}: {parentId: string}) => ({
parent: {_type: 'reference', _ref: parentId},
}),
}
return [...prev, categoryChild]
},
},
})The key point: templates must be a property within the schema object, not a sibling to it.
Your Structure Builder code using S.initialValueTemplateItem('category-child', { parentId: parent._id }) is actually correct according to the official Parent/Child Taxonomy guide. The two-parameter syntax (template ID as first string parameter, parameters as second object parameter) is the documented and correct API for S.initialValueTemplateItem().
If moving the templates configuration inside the schema object doesn't solve it, double-check that:
- The template
id('category-child') matches exactly what you're referencing in the Structure Builder - There are no typos in the template ID
- You've restarted your dev server after making config changes
This was exactly the issue in a community discussion where someone had the identical error - they confirmed: "I just realized what I did, a silly little mistake. I placed the templates outside of the schema object in sanity.config.ts 😛"
The reason you can access documents through the sub-folders is that those lists likely don't use the initialValueTemplates configuration, so they don't trigger this validation error. Once your template is properly registered within the schema object, the "All" folder should work correctly too!
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.