Error visiting localhost:3333 after creating Sanity Studio in Turborepo with pnpm
This is a known issue when running Sanity Studio in a monorepo setup with pnpm and Turborepo! The error you're encountering is related to Vite's file system restrictions in monorepo environments.
Since Sanity Studio v3 uses Vite as its build tool, Vite has security restrictions that prevent serving files from outside the workspace root by default. In a monorepo, this becomes problematic because pnpm creates symlinks to shared dependencies in the monorepo root, which Vite blocks by default.
The Solution
You need to configure Vite's server.fs.allow option in your sanity.config.ts (or .js) file. Add the vite configuration to tell Vite to allow access to your monorepo root:
import {defineConfig} from 'sanity'
import {searchForWorkspaceRoot} from 'vite'
export default defineConfig({
// ... your other config
vite: {
server: {
fs: {
allow: [searchForWorkspaceRoot(process.cwd())]
}
}
}
})The searchForWorkspaceRoot utility from Vite will automatically find your monorepo root (whether it's Turborepo, pnpm workspaces, or Yarn workspaces) and allow Vite to serve files from there.
Alternative Approach
If you need more control, you can also explicitly specify directories:
import {defineConfig} from 'sanity'
import path from 'path'
export default defineConfig({
// ... your other config
vite: {
server: {
fs: {
allow: [
// Allow serving files from the monorepo root
path.resolve(__dirname, '../..'),
// Or use searchForWorkspaceRoot
// searchForWorkspaceRoot(process.cwd())
]
}
}
}
})Why This Happens
The issue is specific to:
- Monorepo setups (Turborepo, Nx, pnpm workspaces, etc.)
- pnpm's symlink strategy for dependency management
- Vite's security model (which Sanity Studio v3 uses)
When pnpm installs dependencies in a monorepo, it creates symlinks to a shared node_modules at the workspace root. Vite sees these as being outside the "allowed" directory and blocks access, causing the error at localhost:3333.
After adding this configuration, restart your dev server with pnpm run dev and the error should be resolved!
Show original thread2 replies
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.