How to hide Vision plugin in production using sanity.json config?
Looking at your configuration, I can see the issue! The "env" property you're using is from Sanity Studio v2 (which used sanity.json), but that configuration format doesn't work in Studio v3+ (which uses sanity.config.ts or sanity.config.js).
Sanity Studio v2 is now deprecated, and the sanity.json configuration file with the "env" property is no longer the way to conditionally load plugins.
For Studio v3, you need to conditionally add plugins in your sanity.config.ts (or .js) file using JavaScript logic. Here's how to hide the Vision plugin in production:
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {visionTool} from '@sanity/vision'
export default defineConfig({
name: 'default',
title: 'My Project',
projectId: 'your-project-id',
dataset: 'production',
plugins: [
structureTool(),
// Only add Vision plugin in development
...(process.env.NODE_ENV === 'development' ? [visionTool()] : [])
],
// ... rest of your config
})The key is using the spread operator (...) with a conditional that checks process.env.NODE_ENV. When you build for production (using sanity build or deploying), NODE_ENV will be set to 'production', and the Vision plugin won't be included.
Alternatively, you can use a more explicit approach:
const plugins = [structureTool()]
if (process.env.NODE_ENV === 'development') {
plugins.push(visionTool())
}
export default defineConfig({
// ... config
plugins,
})If you're still using Studio v2, you should consider migrating to v3 since v2 support ended in December 2023. The "env" property in sanity.json was never a standard feature for conditional plugin loading in v2 either—you'd need to use JavaScript-based configuration even then.
Show original thread1 reply
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.