How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Sanity V3 build fails in Netlify production with legacy package errors

2 repliesLast updated: Nov 30, 2025

Hey Everyone,I recently upgrade my Sanity project from V2 to V3. Although it builds fine in my local machine, the build fails in the production environment in Netlify.
I had this same issue when I was building in QA environment in Netlify, and apparently, it was because the .nvmrc file in Sanity code was of an older version. I fixed that and build was success in QA environment for Netlify. But Now I have the same issue in prod, even with the updated node version.

Issue: During Sanity build, it is trying to access the packages that no longer exists in Sanity V3, i.e,
user F/core
AI Update

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:

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:

4. Check Your Build Command

Make sure your Netlify build command is using the v3 command. It should be:

npm run build
# or
sanity build

5. 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:

Common places these might hide:

Complete Migration Checklist

According to the Sanity v2 to v3 migration guide, you should:

Quick Debug Steps for Netlify

To identify exactly what's causing the issue:

If you're still stuck after trying these steps, please share:

The Migration Cheat Sheet is also a great quick reference for common v2 to v3 code conversions!

Show original thread
2 replies

Was this answer helpful?

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.

Related contributions