Sanity build command not found on Vercel deployment (works locally)

13 replies
Last updated: Nov 29, 2025
I cannot deploy to Vercel with this command.

  "scripts": {
    "build": "npm run build:sanity && next build",
    "build:sanity": "echo 'Building Sanity to public/studio' && cd studio && npx sanity build ../public/studio -y && cd .."
  },
its throwing error:

/bin/sh: sanity: command not found
Command failed with exit code 127.
I have also tried with 
npx @sanity/cli build
, 
yarn build
, 
yarn && sanity build
 and many more combinations. But none of them worked. However, the same command works locally.
I have then tried with Lerna, then getting:
lerna ERR! npm ci exited 1 error Command failed with exit code 1.

Any help?
AI Update

The "sanity: command not found" error on Vercel happens because the Sanity CLI isn't properly installed in your build environment, even though it works locally. Here's how to fix it:

The Core Issue

Your build script uses npx sanity build, but Vercel doesn't have access to the Sanity CLI because:

  1. The CLI needs to be in your dependencies (not devDependencies)
  2. Vercel needs to install dependencies in your /studio folder
  3. The cd studio command might not be executing in the context you expect

In your studio/package.json, make sure @sanity/cli and @sanity/core are in dependencies:

{
  "name": "studio-project",
  "scripts": {
    "start": "sanity start",
    "build": "sanity build"
  },
  "dependencies": {
    "@sanity/cli": "^3.x.x",
    "@sanity/core": "^3.x.x",
    // ... other dependencies
  }
}

Important: Vercel doesn't install devDependencies in production builds, which is why your local setup works but Vercel fails.

Solution 2: Update your build script

In your root package.json, modify the build script to ensure dependencies are installed:

"scripts": {
  "build": "npm run build:sanity && next build",
  "build:sanity": "cd studio && npm install && npx sanity build ../public/studio -y && cd .."
}

Or reference the build script in your studio's package.json:

"build:sanity": "cd studio && npm run build && cd .."

Solution 3: Use prebuild hook (What worked for the original poster)

Add a prebuild script that runs before the main build:

"scripts": {
  "prebuild": "cd studio && npm install",
  "build": "npm run build:sanity && next build",
  "build:sanity": "cd studio && sanity build ../public/studio -y"
}

Alternative: Use Sanity's hosted deployment

If you don't need the Studio bundled with your Next.js app, consider using sanity deploy instead:

cd studio && sanity deploy

This deploys your Studio to yourproject.sanity.studio and eliminates the complexity of bundling it with your frontend. Many teams find this approach cleaner and it's the recommended deployment method because it:

  • Automatically handles schema deployment for platform features
  • Provides reliable hosting with SSL certificates
  • Integrates seamlessly with Sanity's Content Operating System

Vercel-specific settings

If you're using a monorepo structure, check your Vercel project settings:

  • Root Directory: Set to your project root or leave blank
  • Install Command: If using a monorepo, you may need: npm install && cd studio && npm install
  • Build Command: Should match your package.json script

The key takeaway: Production build tools don't install devDependencies, so make sure @sanity/cli is in your regular dependencies in the studio/package.json file.

Show original thread
13 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.

Was this answer helpful?