sanity-io / next-sanity

Sanity.io toolkit for Next.js
https://www.sanity.io/
MIT License
755 stars 91 forks source link

Desk crashes with Uncaught Error: Workspace: missing context value #724

Open ilyagru opened 11 months ago

ilyagru commented 11 months ago

Describe the bug

When embedding the studio into a Next.js app, the desk tool crashes and throws an error "Uncaught Error: Workspace: missing context value". What's interesting is that I have 2 identical projects and one of them works fine, the other crashes with the mentioned error. If I build the studio separately and go to localhost:3333/studio, it doesn't crash.

What could be the issue?

To Reproduce

Steps to reproduce the behavior:

sanity.config.ts

import { defineConfig, isDev } from 'sanity'
import { deskTool } from 'sanity/desk'
import { visionTool } from '@sanity/vision'
import { schemaTypes } from './src/schemas'

export default defineConfig({
  name: 'default',
  title: 'app-studio',
  projectId: '...',
  dataset: 'production',
  basePath: '/studio',
  plugins: [
    deskTool(),
    ...(isDev
      ? [
          visionTool({
            defaultApiVersion: 'v2023-11-02',
            defaultDataset: 'production'
          })
        ]
      : [])
  ],
  schema: {
    types: schemaTypes
  }
})

Expected behavior

No error is thrown.

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot 2023-11-02 at 11 34 31 Screenshot 2023-11-02 at 11 33 36 Screenshot 2023-11-02 at 11 34 17

Which versions of Sanity are you using?

Sanity v3.19.0 Next.js both v13.5.5 and v14.0.1

What operating system are you using?

macOS 14.1

Which versions of Node.js / npm are you running?

Run npm -v && node -v in the terminal and copy-paste the result here.

Node.js v18.18.2 pnpm v8.10.0

Additional context

Add any other context about the problem here.

Security issue?

Any security issues should be submitted directly to security@sanity.io. In order to determine whether you are dealing with a security issue, ask yourself these two questions:

Steffi3rd commented 10 months ago

Same problem

oblodev commented 10 months ago

Got the same problem. Same node version: image

jessetan commented 9 months ago

I'm hitting this issue as well when trying to create a custom nav bar using the instructions at https://www.sanity.io/docs/studio-components-reference#db9fc60782a3

npm v10.2.3 Node v21.2.0

manimul commented 9 months ago

I just had this issue happening quite randomly on a Remix project with an embedded Studio. No work was being done on the Sanity schemas or setup when it started happening. It would crash when i went to add new content on a Sanity document. I was able to get around it by opening the local Studio in a new browser on Incognito mode, and logging in again to Sanity, So perhaps it's some caching issue?

federicocappellotto97 commented 8 months ago

Same here

"next": "14.0.4",
"next-sanity": "^7.0.10",
"@sanity/vision": "^3.24.1",
"sanity": "^3.24.1"

Worked before updating, now i get Error: Workspace: missing context value

Vinam09 commented 8 months ago

Running into the same issue with my project, Has anyone found a workaround?

abdealisaria commented 8 months ago

Same error: missing context value. My local sanity studio works fine using npm run dev When I use sanity deploy that studio throws the same error. image

fostimus commented 7 months ago

Same here

alexanderkalachev commented 4 months ago

After latest updates, same issue is surfaced when hosting on Vercel, but locally all works fine. Frustrating, because absolutely not clear how to fix it.

alexanderkalachev commented 3 months ago

Is there any progress on this issue? I've tried many different approaches to find what causes that, but couldn't find it.

notflip commented 2 months ago

I've encountered this issue as well, after adding a plugin to Sanity.

Kakha01 commented 1 month ago

I fixed this issue by

  1. deleting node_modules folder in my project directory
  2. clearing pnpm cache with pnpm store prune in terminal
  3. and reinstalling packages with pnpm install