Issue with Sanity V3 build failing in production environment in Netlify.
I understand you're facing a frustrating build issue after upgrading from Sanity v2 to v3. Even though your local build works fine and you've updated the Node version in your .nvmrc file, your production Netlify build is still failing because it's trying to access packages that no longer exist in v3 (like @sanity/core and @sanity/base).
This is a common migration issue. Here's what's happening and how to fix it:
The Root Cause
In Sanity v3, several packages were deprecated and removed, including:
@sanity/base@sanity/core@sanity/default-layout@sanity/default-login@sanity/desk-tool
These packages have been consolidated into the single sanity package. If your build is still trying to import from these packages, it will fail.
Steps to Fix Your Production Build
1. Remove Deprecated Packages from package.json
Make sure these packages are completely removed from your package.json dependencies:
// Remove these if they exist:
"@sanity/base"
"@sanity/core"
"@sanity/default-layout"
"@sanity/default-login"
"@sanity/desk-tool"2. Update Your Imports Throughout Your Codebase
Search your entire project for any imports from the old packages and update them. Common patterns to find and replace:
Old v2 imports:
import sanityClient from "part:@sanity/base/client"
import schema from 'part:@sanity/base/schema'
import userStore from "part:@sanity/base/user"New v3 imports:
import {useClient} from 'sanity'
import {useSchema} from 'sanity'
import {useCurrentUser} from 'sanity'3. Clear Netlify's Build Cache
Sometimes Netlify caches dependencies. Try:
- Go to your Netlify site settings
- Navigate to "Deploys" → "Deploy settings"
- Click "Clear cache and retry deploy"
4. Check Your Build Command
Make sure your Netlify build command is using the v3 command. It should be:
npm run build
# or
sanity build5. Verify node_modules Isn't Cached
If you have a node_modules directory committed to your repo (you shouldn't), remove it and add it to .gitignore.
6. Check for Hidden Import References
Search your entire codebase (including config files) for these patterns:
part:@sanity/@sanity/base@sanity/core
Common places these might hide:
- Custom plugins
sanity.config.js(should be updated fromsanity.json)- Custom input components
- Structure builder configurations
Complete Migration Checklist
According to the Sanity v2 to v3 migration guide, you should:
- ✅ Update Node version (you've done this)
- ✅ Remove deprecated packages
- ✅ Install
sanity@latest - ✅ Update dependencies:
"@sanity/ui": "^1""react": "^18.2.0""react-dom": "^18.2.0"
- ✅ Move configuration from
sanity.jsontosanity.config.js - ✅ Replace all
import X from "part:X"statements - ✅ Update any plugins to v3-compatible versions
Quick Debug Steps for Netlify
To identify exactly what's causing the issue:
- Check your Netlify build logs for the specific error message
- Look for which file is trying to import the deprecated package
- Search that file path in your codebase and update the imports
If you're still stuck after trying these steps, please share:
- The exact error message from your Netlify build logs
- Your
package.jsondependencies - Any custom plugins you're using
The Migration Cheat Sheet is also a great quick reference for common v2 to v3 code conversions!
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.