Trouble deploying to Vercel with Sanity build command

13 replies
Last updated: Jul 14, 2021
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?
Jul 14, 2021, 1:03 PM
Do you have
as a dependency in your
Jul 14, 2021, 1:07 PM
yes, I have it as dev dependencies for next.js root folder as well.
it sometime throws "some commands not available until sanity install"
Jul 14, 2021, 1:09 PM
btw, the sanity project is in the /studio folder
Jul 14, 2021, 1:09 PM
Fwiw, I have
as a normal, non-dev dependency in my studio’s
and run
sanity build
on netlify with no issue
Jul 14, 2021, 1:12 PM
It is non-dev, because it is essential to have the cli available in production to do the actual building
Jul 14, 2021, 1:14 PM
I guess its because I'm installing next.js in the root then sanity in /studio folder. And its vercel.
Also, if we are using
then we don't need it to be in package.json right?
Jul 14, 2021, 1:14 PM
Locally, I guess you could use npx to run anything inside the
folder, but for your setup to work, I guess you need to make sure that whatever you need to run (in this case the sanity cli) is also available on the build server (in this case Vercel).
Vercel doesn’t know what’s inside your local node_modules folder, but will install everything in your
before building your site.
Jul 14, 2021, 1:25 PM
looks something like this:
  "name": "studio-project",
  "scripts": {
    "start": "sanity start",
    "build": "sanity build"
  "dependencies": {
    "@sanity/cli": "^2.11.0",
  "devDependencies": {
    "babel-eslint": "^10.1.0",
Jul 14, 2021, 1:27 PM
I guess you need to make sure that
is available in the
as a non-dev wherever your trying to use the command
sanity build
Jul 14, 2021, 1:29 PM
yes, still showing error. @core isalready there in the package.
I guess the issue is vercel is not taking the command of
cd studio
somehow. its trying to run from root.

@sanity/core not installed in current project
18:58:04.018  	Project-specific commands not available until you run `sanity install`
18:58:04.023  	Error: Command "build" is not available outside of a Sanity project context.
18:58:04.023  	Run the command again within a Sanity project directory, where "@sanity/core"
Jul 14, 2021, 1:30 PM
you might need to do npm install inside of the studio directory, i.e
cd studio && npm i && sanity build
Jul 14, 2021, 1:45 PM
What I would try:1. make sure
in your
as a normal dependency2. Make sure you have a “build command” in
3. In your project root
, the build:sanity command could cd into the studio and run the studio’s build command
"build:sanity": "cd studio && npm run build"

Jul 14, 2021, 1:46 PM
Thanks man, I finally tried with
and it worked.
Yes, I also made sure to install
before that. Got error with another devDependancy. So I guess you are right. devdependency doesn't work in Vercel.
Thanks again.
Jul 14, 2021, 2:42 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?