Sanity project missing schema.js file after installation with clean template

32 replies
Last updated: Dec 9, 2022
I've started multiple times from the tips on the sanity page which is to create a project like this but it still installs without a schema.js file:
npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset production

AI Update

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 production

You'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:

  1. Create a new schema file in src/schemaTypes/, for example postType.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',
    }),
  ],
})
  1. 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 schemaTypes folder with an index.ts file
  • 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 blog

This 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 thread
32 replies
could you try with the blog template?
I'll try that and see if it works.
Thanks for tips btw.
Do you suggest using typescript if your going to use react,js?
with react? absolutely
with vue it is currently pretty weird using typescript
ok great because it asks more questions now when setting up sanity lol. I've heard of vue but never used it yet. My project was actully fine before the new update so it's little overwhelming for a newbie such as myself
I just ended up deleting everything and starting over.
did you end up getting the schema file?
if not, it is pretty easy to manually set up
also now i get a question that asks which package manager should i use to install dependencies. npm or manual and i have npm installed btw. I haven't finished the install yet because im not sure if i should use npm or install dependencies manually
use yarn
npm install -g yarn
it is several times faster and has some extra features
Ahh ok cool. the other day i had a yarn file but now when i install its gone. i had a yarn.lock file yesterday which automatically came but now its like totally different
yes. npm uses package-lock.json and yarn uses yarn.lock
heres the npm or manual question
you could go manual and later run
yarn install
Awww ok I'll do that
The blog one didn't give me a schema.js file either
user E
what does your file structure look like after you finish initializing a project?
Hi there, Ima take a screenshot really quick and send it
Ok this is the one from yesterday when everything was working fine:
Now it looks like this when i install sanity.io
There's no more schema.js file and on the sanity website I was following along with the guide and it says to put your schemas in the schema.js file but unfortunately when I install sanity now the file structure is totally different.
Ah, ok I see the confusion. The first one you shared is a V2 Studio, but the new V3 version is structured completely differently. You'll add your schemas to your index.js in the schemas directory instead.
I caught this too; it mentions a schema.js file here as well but I can't find the schema.js file. The schema.js file is mentioned in a comment at the top in the screenshot.
There's more info on how a project is structured now here .
Awww ok I see, thanks for the help. I did notice an index.js when I installed sanity earlier today using an empty project
You're welcome! This quite literally changed today, so it's understandable that it was confusing!
Hi, I have the same problem. When I run the project I can't see schema.js in my schema. Any body can help.
In my schema only can see index.js.

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?