Module not found error: Can't resolve 'part:@sanity/desk-tool/structure

14 replies
Last updated: Jun 11, 2022
[NOT SOLVED]Hello everyone, hope you are all doing great. I have an issue with structure-builder and hope someone could give me a help with it. I was following
https://www.sanity.io/guides/getting-started-with-structure-builder , but I can't seem to make it work. Issue I am facing is :
Module not found: Error: Can't resolve 'part:@sanity/desk-tool/structure?'

I tried researching more about this module, but any help I found online didn't work for me. Could someone please aid me with this ?
AI Update

I can see you're running into a classic version mismatch issue! The error you're getting is because you're following a guide written for Sanity Studio v2, but you're likely using Sanity Studio v3 (or v4). The part: import system was completely removed in Studio v3, which is why you're getting that "Can't resolve" error.

The Solution

In Studio v3+, the import path has changed. Instead of:

// ❌ This is v2 syntax - won't work in v3+
import S from 'part:@sanity/desk-tool/structure-builder'

You need to use:

// ✅ This is v3+ syntax
import {structureTool} from 'sanity/structure'

How to Set Up Structure Builder in v3+

Here's the modern way to configure the Structure Builder:

1. Create a structure file (e.g., structure/index.ts or structure.ts):

import type {StructureResolver} from 'sanity/structure'

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

2. Import and configure it in your sanity.config.ts:

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

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

What Changed Between v2 and v3?

  • v2: Used the part: system and required a deskStructure.js file
  • v3+: Uses standard ES module imports and configures everything in sanity.config.ts
  • The Structure Builder object (S) works mostly the same, but how you import and configure it is completely different

Updated Documentation

The guide you were following is outdated. For current documentation, check out:

The good news is that once you update your imports and configuration structure, most of your actual Structure Builder code (the S.list(), S.documentTypeListItem(), etc.) will work with minimal changes!

Show original thread
14 replies
Did you define the part in your Sanity.json and a file at that path exists?
{
  "root": true,
  "project": {
    "name": "digitale-grundung"
  },
  "api": {
    "projectId": "xxxxxxxx",
    "dataset": "production"
  },
  "plugins": [
    "@sanity/base",
    "@sanity/components",
    "@sanity/default-layout",
    "@sanity/default-login",
    "@sanity/dashboard",
    "@sanity/desk-tool"
  ],
  "env": {
    "development": {
      "plugins": [
        "@sanity/vision"
      ]
    }
  },
  "parts": [
    {
      "name": "part:@sanity/desk-tool/structure",
      "path": "./deskStructure.js"
    },
    {
      "name": "part:@sanity/base/schema",
      "path": "./schemas/schema"
    }
  ]
}
this would be my structure of sanity.json
And
deskStructure.js
exists?
Yes, this is how it looks :
import S from '@sanity/desk-tool/structure-builder'

export default () =>
  S.list()
    .title('Contents')
    .items(
      S.documentTypeListItems()
    )
pretty basic stuff to make it start working, would customize it further after
It looks good. Even with a restart, it doesn‘t work?
Sadly, not. Tried removing
node_modules
as well, didn't help. Always getting
Module not found: Error: Can't resolve 'part:@sanity/desk-tool/structure?'
Would you mind sharing your structure in
node_modules/@sanity/desk-tools/
If you search for this in your codebase, do you have more hits than just the
sanity.json
one?
This issue is being triggered inside of
/node_modules/@sanity/structure/lib/parts/userStructure.js
. Full issue is :

Module not found: Error: Can't resolve 'part:@sanity/desk-tool/structure?' in '/home/aljosa/Documents/projects/xxxxxx/frontend/sanity/node_modules/@sanity/structure/lib/parts'
Which version of Sanity are you using?
@sanity/cli version 2.30.0

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?