Issues with deploying GraphQL after upgrading from V2 to V3 Sanity
I can see you're hitting a specific error related to import.meta.env.PRODUCTION after upgrading to Sanity v3. This is a common issue that happens when your configuration files try to use environment variables that aren't available in the Node.js context where sanity graphql deploy runs.
The problem is that import.meta.env is a Vite-specific feature that only works in the browser/build context of your Studio, but the GraphQL deploy command runs in Node.js, where import.meta.env is undefined. When your config tries to read import.meta.env.PRODUCTION, it fails because import.meta.env itself is undefined.
The Fix
You need to update your sanity.config.ts (or .js) file to handle this properly. Here are the most common solutions:
Option 1: Use process.env instead (recommended)
Replace import.meta.env.PRODUCTION with process.env.NODE_ENV:
import { defineConfig } from 'sanity'
export default defineConfig({
name: 'default',
title: 'My Studio',
projectId: 'your-project-id',
dataset: process.env.NODE_ENV === 'production' ? 'production' : 'development',
// rest of your config
})Option 2: Add a fallback check
If you need to support both contexts, add a check:
const isProduction = typeof import.meta !== 'undefined'
? import.meta.env?.PRODUCTION
: process.env.NODE_ENV === 'production'
export default defineConfig({
dataset: isProduction ? 'production' : 'development',
// rest of your config
})Option 3: Remove conditional logic for GraphQL
If you're only deploying GraphQL for production, you can hardcode it:
export default defineConfig({
dataset: 'production',
// rest of your config
})Why This Happens
In v2, the configuration was simpler and didn't use Vite. V3 introduced Vite as the build tool, which provides import.meta.env for the Studio UI. However, CLI commands like sanity graphql deploy still run in Node.js and don't have access to Vite's environment variables.
The error message "Cannot read properties of undefined (reading 'PRODUCTION')" literally means it's trying to access undefined.PRODUCTION because import.meta.env is undefined in the Node.js context.
After making these changes, your sanity graphql deploy command should work properly!
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.