Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with workspaces in Sanity V3 upgrade

5 replies
Last updated: Jan 11, 2023
Hello! 👋
I've ran and upgrade from Sanity V2 to Sanity V3, although seem to be running into issues with workspaces. I have two workspaces dev and production, although it seems that the desk always defaults to dev, similarly when I change the URL to production, it comes up with an error message "Workspace not found". I've pasted the config below, any idea where I might be going wrong? The dropdown at the top is also not appearing
Jan 8, 2023, 11:07 PM
// sanity.config.js
import { defineConfig } from "sanity";
import { deskTool } from 'sanity/desk'
import schemas from './schemas/schema'
import { table } from '@sanity/table';
import { colorInput } from "@sanity/color-input";
import deskStructure from './sidebar'
import { visionTool } from '@sanity/vision'

export default defineConfig({
  title: "XX Dev",
  projectId: "XX",
  dataset: "dev",
  name: "dev",
  basePath: '/dev',
  plugins: [deskTool({structure: deskStructure}),
    visionTool(),
    table(),
    colorInput()],
    tools: (prev) => {
      // 👇 Uses environment variables set by Vite in development mode
      if (import.meta.env.DEV) {
        return prev
      }
      return prev.filter((tool) => tool.name !== 'vision')
},
  schema: {
    types: schemas,
  },
  document: {
    newDocumentOptions: (prev, { creationContext }) => {
      if (creationContext.type === 'global') {
        return prev.filter((templateItem) => templateItem.templateId != 'settings')
      }
      return prev
    },
    actions: (prev, { schemaType }) => {
      if (schemaType === 'settings') {
        return prev.filter(({ action }) => !['unpublish', 'delete','duplicate'].includes(action))
      }
      return prev
    },
  },
},
{
  title: "XX Prod",
  projectId: "XX",
  dataset: "production",
  name: "production",
  basePath: '/production',
  plugins: [deskTool({structure: deskStructure}),
    visionTool(),
    table(),
    colorInput()],
    tools: (prev) => {
      // 👇 Uses environment variables set by Vite in development mode
      if (import.meta.env.PRODUCTION) {
        return prev
      }
      return prev.filter((tool) => tool.name !== 'vision')
},
  schema: {
    types: schemas,
  },
  document: {
    newDocumentOptions: (prev, { creationContext }) => {
      if (creationContext.type === 'global') {
        return prev.filter((templateItem) => templateItem.templateId != 'settings')
      }
      return prev
    },
    actions: (prev, { schemaType }) => {
      if (schemaType === 'settings') {
        return prev.filter(({ action }) => !['unpublish', 'delete','duplicate'].includes(action))
      }
      return prev
    },
  },
});

Jan 8, 2023, 11:08 PM
// sanity.cli.js
import {defineCliConfig} from 'sanity/cli'

export default defineCliConfig({
  api: {
    projectId: 'XX', // replace value with your own
    dataset: 'production' // replace value with your own
  }
})

Jan 8, 2023, 11:09 PM
Hey
user P
! If you’re defining two different environments, you need to pass an array into your
defineConfig
. Just wrap your two config objects in an array and you should be all set! You’re probably getting the workspace not defined error because you’re trying to navigate to something like
<http://localhost:3333/desk>
instead of
<http://localhost:3333/<basePath>/desk>
.
Jan 10, 2023, 9:14 PM
Doh! Such a noobie mistake! Works like charm now, thank you!
Jan 10, 2023, 9:17 PM
Haha, I’ve made that exact mistake before.
Jan 11, 2023, 12:29 AM

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.

Was this answer helpful?