Troubleshooting adding a schema to Sanity project
23 replies
Last updated: Jun 3, 2023
G
Hi everyone,
I’m following the tutorial on getting my first schema set up, and I copied and pasted the example schema for pet into the schemas folder, but Sanity is telling me I haven’t provided a type or a title…. any thoughts on what I might be doing wrong?
I’m following the tutorial on getting my first schema set up, and I copied and pasted the example schema for pet into the schemas folder, but Sanity is telling me I haven’t provided a type or a title…. any thoughts on what I might be doing wrong?
Jun 3, 2023, 7:02 PM
R
Hi Gary!
Sounds like it hasn’t been added to the either a primary schema file or to the
Sounds like it hasn’t been added to the either a primary schema file or to the
sanity.config.tsfile.
Jun 3, 2023, 7:06 PM
R
Here’s a project I’m working on:
I organize my schema files by type:
Here’s an example of a starter’s sanity.config.ts:
I organize my schema files by type:
File - sanity.config.ts
export default defineConfig({
...
schema: {
types: [ ...siteSettings, ...navigation, ...objects, ...documents, ...taxonomies]
},
Here’s an example of a starter’s sanity.config.ts:
File - sanity.config.ts
export default defineConfig({
...
//edit schemas in './sanity/schema'
schema,
...
File - schema.ts:
import { SchemaTypeDefinition } from 'sanity'
import post from "./post";
export const schema: { types: SchemaTypeDefinition[] } = {
types: [
post
],
}
Jun 3, 2023, 7:11 PM
G
Hi Ryan!
I
think I’m doing the same basic thing you have in your code above but on a smaller scale. I’ll share my files below:
I
think I’m doing the same basic thing you have in your code above but on a smaller scale. I’ll share my files below:
Jun 3, 2023, 7:19 PM
R
Feel free to post them as a private gist if it’s easier.
Jun 3, 2023, 7:19 PM
G
schemas/pet.ts
export default { name: 'pet', type: 'document', title: 'Pet', fields: [ { name: 'name', type: 'string', title: 'Name' } ] }
Jun 3, 2023, 7:20 PM
G
schemas/index.ts
import pet from './pet' export const schemaTypes = ['pet']
Jun 3, 2023, 7:20 PM
G
That’s all I have so far… let me know if you want a screen grab of the errors
Jun 3, 2023, 7:20 PM
G
They basically say “unnamed_type_index_0”
Jun 3, 2023, 7:22 PM
R
Do you have this added to your config?
Jun 3, 2023, 7:23 PM
G
Yup
Jun 3, 2023, 7:24 PM
R
Let’s see that section
Jun 3, 2023, 7:24 PM
G
One sec…
Jun 3, 2023, 7:24 PM
G
export default defineConfig({ name: 'default', title: 'indigo-elephant', projectId: '3uxw0mxz', dataset: 'production', plugins: [deskTool(), visionTool(), ...(isDev ? devOnlyPlugins : [])], schema: { types: [...schemaTypes], }, })
Jun 3, 2023, 7:24 PM
G
And schemaTypes are imported correctly
Jun 3, 2023, 7:24 PM
G
also tried:
types: schemaTypes (without destructuring)
Jun 3, 2023, 7:25 PM
R
One sec.
Jun 3, 2023, 7:26 PM
R
Try removing the quotes from [‘pet’]
Jun 3, 2023, 7:28 PM
R
in your index.ts
Jun 3, 2023, 7:29 PM
G
well that’s embarrassing….
Jun 3, 2023, 7:29 PM
R
No. That’s everyones everyday with a quote somewhere.
Jun 3, 2023, 7:29 PM
G
I’m going to check the sanity docs… I could have sworn it was in quotes there also… my pride is at stake here, lol
Jun 3, 2023, 7:30 PM
R
LMK if it’s in the docs. Glad you are onto the next step:)
Jun 3, 2023, 7:31 PM
G
Nope, the docs were correct… thanks very much for the help!!
Jun 3, 2023, 7:33 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.