Discussion about resolving an error in setting up a custom desk structure in Sanity.io

42 replies
Last updated: Mar 26, 2021
Hey everyone! I was just trying to setup a custom desk strcuture following this article here: https://www.sanity.io/guides/getting-started-with-structure-builder But I always get this error:
Any ideas? Thanks!
AI Update

I can see you're running into a common issue when setting up custom desk structure! The article you're following is likely for an older version of Sanity Studio. There have been some important changes in recent versions that are causing your error.

The Problem

In Sanity Studio v3+, the Structure Builder setup has changed from earlier versions. The most common issues are:

  1. Import path changed: The old 'sanity/desk' import is now 'sanity/structure'
  2. Plugin renamed: deskTool() is now structureTool()
  3. Function signature: The structure function receives the Structure Builder as a parameter differently

The Solution

Here's how to set it up correctly for modern Sanity Studio:

In your sanity.config.ts:

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'

export default defineConfig({
  // ... your other config
  plugins: [
    structureTool({
      structure: (S) =>
        S.list()
          .title('Content')
          .items([
            S.documentTypeListItem('post').title('Posts'),
            S.documentTypeListItem('author').title('Authors'),
            // ... more items
          ])
    }),
    // ... other plugins
  ],
})

Or extract it to a separate file (structure/index.ts):

import type {StructureResolver} from 'sanity/structure'

export const structure: StructureResolver = (S) =>
  S.list()
    .title('Content')
    .items([
      S.documentTypeListItem('post').title('Posts'),
      S.documentTypeListItem('author').title('Authors'),
    ])

Then import it:

import {structureTool} from 'sanity/structure'
import {structure} from './structure'

export default defineConfig({
  plugins: [
    structureTool({structure}),
  ],
})

Key Changes to Remember

  • ✅ Import from 'sanity/structure' (not 'sanity/desk')
  • ✅ Use structureTool() (not deskTool())
  • ✅ The structure function signature is (S) => S.list()... or (S, context) => S.list()...

The Structure Builder documentation has been updated with all the current syntax, so that's your best reference going forward!

This is my `deskStructure.js`:

import S from "@sanity/desk-tool/structure-builder";

export default () =>
  S.list()
    .title("Content")
    .items([
      S.listItem()
        .title("Settings")
        .child(
          S.document().schemaType("siteSettings").documentId("siteSettings")
        ),
      ...S.documentTypeListItems(),
    ]);
Which version are you on,
user N
?
hey
uhm
"dependencies": {
    "@sanity/base": "^2.7.1",
    "@sanity/components": "^2.2.6",
    "@sanity/core": "^2.7.1",
    "@sanity/dashboard": "^2.7.0",
    "@sanity/default-layout": "^2.7.1",
    "@sanity/default-login": "^2.7.0",
    "@sanity/desk-tool": "^2.7.1",
    "@sanity/structure": "^2.7.1",
    "@sanity/vision": "^2.7.0",
    "prop-types": "^15.7",
    "react": "^17.0",
    "react-dom": "^17.0"
  },
this?
Is that not a weird require to have a ? At the end?
It's like that on next branch.
Hey man. what do you mean?
How does your
sanity.json
look like?
{
  "root": true,
  "project": {
    "name": "Minoo Website"
  },
  "api": {
    "projectId": "ab10er4l",
    "dataset": "production"
  },
  "plugins": [
    "@sanity/base",
    "@sanity/components",
    "@sanity/default-layout",
    "@sanity/default-login",
    "@sanity/desk-tool"
  ],
  "parts": [
    {
      "name": "part:@sanity/base/schema",
      "path": "./schemas/schema.js"
    },
    {
      "name": "part:@sanity/desk-tool/structure",
      "path": "./deskStructure.js"
    }
  ]
}
Did you recently add the
@sanity/structure
package and forgot to
npm i
?
npm? I have a yarn.lock..
OK. Did you recently add
@sanity/structure
manually in your
package.json
and not run
yarn
?
also where would I add
@sanity/structure
?
ah .. no i dont think so
hm maybe? I was trying to get rid of this error and might have done something like
sanity install @sanity/structure
try removing your
node_modules
and run
sanity install
again.
😕
Your
deskStructure.js
file is on your root?
Sanity is in
/studio
and this is the directory strcuture in there:
OK. That should be fine.Could you try removing
@sanity/structure
as a direct dependency, remove
node_modules
and to
sanity install
again?
hold on 🙂
Meeehhh..
so sorry man thanks for taking the time
No worries, I'm here to help. 🙂
my
package.json
looks like this now:

{
  "name": "minoowebsite",
  "private": true,
  "version": "1.0.0",
  "description": "",
  "main": "package.json",
  "author": "Nils Borgböhmer <nils@dinghy.studio>",
  "license": "UNLICENSED",
  "scripts": {
    "start": "sanity start",
    "build": "sanity build"
  },
  "keywords": [
    "sanity"
  ],
  "dependencies": {
    "@sanity/base": "^2.7.1",
    "@sanity/components": "^2.2.6",
    "@sanity/core": "^2.7.1",
    "@sanity/dashboard": "^2.7.0",
    "@sanity/default-layout": "^2.7.1",
    "@sanity/default-login": "^2.7.0",
    "@sanity/desk-tool": "^2.7.1",
    "@sanity/vision": "^2.7.0",
    "prop-types": "^15.7",
    "react": "^17.0",
    "react-dom": "^17.0"
  },
  "devDependencies": {}
}
Not sure what is going on here. This should work. 🤔
I agree!
😄
this is also not my first sanity setup..
Woops. You have a type in your
deskStructure.js
file.
WHAT!
Typo*
Where?
Your
deskStructure.js
file. It's called
deskStucture.js
.
NOOOOOOO
hehe … man
thanks a lot!
case closed
😄 Happy to help.
user P
I got the same error today but because I was renaming by deskStructure file from .js to .ts while sanity.json was still "linking" to the .js file. Maybe it would be worth returning a better error message when the deskStructure file is not found :)

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?