Error with @sanity/desk-tool/structure-builder resolved by using S.list instead of importing directly

7 replies
Last updated: Oct 13, 2021
Hello! I keep getting this sort of error and I cannot understand what might cause it. Is this a versioning issue? All packages are up-to-date (as of time of typing this)
I cannot enter det desk, but Vision plugin works.



TypeError: (0 , _structureBuilder.list) is not a function
    at _default (/static/js/app.bundle.js:168275:49)
    at serializeStructure (/static/js/app.bundle.js:382416:31)
    at <http://localhost:3333/static/js/app.bundle.js:167462:65>
    at Observable._subscribe (/static/js/app.bundle.js:96047:21)
    at Observable._trySubscribe (/static/js/app.bundle.js:2986:25)
    at Observable.subscribe (/static/js/app.bundle.js:2972:22)
    at DistinctUntilChangedOperator.call (/static/js/app.bundle.js:124910:23)
    at Observable.subscribe (/static/js/app.bundle.js:2967:31)
    at MapOperator.call (/static/js/app.bundle.js:27473:23)
    at Observable.subscribe (/static/js/app.bundle.js:2967:31)
AI Update

The error (0, _structureBuilder.list) is not a function indicates an import issue with the Structure Builder API in your Sanity Studio configuration. This is a common problem when migrating to or working with Studio v3, where the import patterns changed significantly.

The Problem

Your code is likely trying to import Structure Builder methods incorrectly. In Studio v3, you need to import the Structure Builder object from the correct location and use it properly in your configuration.

The Solution

Here's how to fix it:

1. Check Your Import in sanity.config.ts

Make sure you're importing and configuring the structureTool correctly:

// sanity.config.ts
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {structure} from './structure'

export default defineConfig({
  // ...other config
  plugins: [
    structureTool({structure}),
    // ...other plugins
  ],
})

2. Check Your Structure File

In your structure definition file (e.g., structure/index.ts or deskStructure.js), make sure you're using the correct import pattern. The S object is provided as a parameter to your structure function, not imported:

// structure/index.ts
import type {StructureResolver} from 'sanity/structure'

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

Don't do this (common mistake):

// ❌ WRONG - Don't import S separately
import S from '@sanity/desk-tool/structure-builder'

3. Common Migration Issues

If you're migrating from Studio v2, note these changes according to the Structure Builder documentation:

  • The package changed from @sanity/desk-tool to sanity/structure
  • You no longer import S directly; it's passed as a parameter to your structure function
  • The tool is now called structureTool() instead of deskTool()

Quick Checklist

  1. ✅ Import structureTool from 'sanity/structure' in your config
  2. ✅ Your structure function receives S as a parameter: (S) => S.list()...
  3. ✅ Remove any old imports from @sanity/desk-tool
  4. ✅ Make sure you're using S.list() not list() directly
  5. ✅ Verify all packages are actually up-to-date: npm outdated or yarn outdated
  6. ✅ If you have multiple structure files, check them all for old import patterns

The fact that Vision plugin works but the desk doesn't confirms this is specifically a Structure Tool configuration issue, not a broader Studio problem. Once you update your imports to the v3 pattern, you should be able to access the desk again.

I have not last it worked, but I did try to comment out more and more of it to see if anything could help.
I did notice that when I changed imports from

import S, { list, listItem, editor, documentTypeList } from '@sanity/desk-tool/structure-builder';
to


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

// Then instead of importing directly, deconstruct from S
const { list, listItem, editor, documentTypeList } = S;
This works
👍
Ah, interesting. Did you notice if this happened after upgrading your Studio or was it totally out of the blue?
So I guess the fix or pattern to avoid it is to use the structure builder parts on this form:
S.list
etc. instead of importing them.

We’ve used it like above for a while so I can’t really tell what we’ve done differently, and I have had my focus on other parts of our project so I am not entirely sure when this bug appeared. It’s been like that on my localhost for at least a week, perhaps more. But, for the same period I know it worked for my colleagues so that’s what was a bit baffling
🙂
The last time something similar happened I deleted my local version and cloned the repository and it worked again, but I cant promise you that it was the exact same issue.

Sorry I don’t have more details about which versions we were on. The reason I upgraded now was an attempt to resolve the issue on mye end, so it definitely wasn’t the last version change that triggered it.
So I guess the fix or pattern to avoid it is to use the structure builder parts on this form:
S.list
etc. instead of importing them.

We’ve used it like above for a while so I can’t really tell what we’ve done differently, and I have had my focus on other parts of our project so I am not entirely sure when this bug appeared. It’s been like that on my localhost for at least a week, perhaps more. But, for the same period I know it worked for my colleagues so that’s what was a bit baffling
🙂
The last time something similar happened I deleted my local version and cloned the repository and it worked again, but I cant promise you that it was the exact same issue.

Sorry I don’t have more details about which versions we were on. The reason I upgraded now was an attempt to resolve the issue on mye end, so it definitely wasn’t the last version change that triggered it.
Thanks for you quick attention, though 👍
Happy to help! I'm curious, though, where did you see that pattern that you were originally using? Was it something you picked up from our docs?
We’ve had id like that since early 2019, so TBH I don’t recall from where we found that pattern. It’s not unlikely that it was something we “creatively” did on our own 😛

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?