Sanity project missing schema.js file after installation with clean template
This is actually expected behavior for the clean template! The --template clean option is specifically designed to create a Sanity project without predefined schemas, giving you a blank slate to start from.
When you run:
npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset productionYou'll get a project structure with a schemaTypes folder that contains only an index.ts file with an empty array:
// src/schemaTypes/index.ts
export const schemaTypes = []This is intentional! The clean template is meant for developers who want to build their schema from scratch without any example content types.
What you should do next
You now need to create your own schema types. Here's how to add your first one:
- Create a new schema file in
src/schemaTypes/, for examplepostType.ts:
// src/schemaTypes/postType.ts
import {defineField, defineType} from 'sanity'
export const postType = defineType({
name: 'post',
title: 'Post',
type: 'document',
fields: [
defineField({
name: 'title',
type: 'string',
}),
],
})- Register it in your schema types index:
// src/schemaTypes/index.ts
import {postType} from './postType'
export const schemaTypes = [postType]About schema.js vs schemaTypes/index.ts
There is no schema.js file in modern Sanity projects because:
- Current Sanity Studio (v3+) uses TypeScript by default
- Schemas are defined in the
schemaTypesfolder with anindex.tsfile - This is the modern approach documented in the opinionated guide to Sanity Studio
If you want example schemas instead
If you'd prefer to start with pre-built example schemas to learn from, use the blog template instead:
npm create sanity@latest -- --template blogThis will give you a complete blog setup with example document types like post, author, and category that you can learn from and modify.
The clean template is working exactly as designed - it provides the basic project structure but leaves all schema definition up to you!
Show original thread32 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.