
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI 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:
id ('category-child') matches exactly what you're referencing in the Structure BuilderThis 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 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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store