Trouble deploying to Vercel with Sanity build command
13 replies
Last updated: Jul 14, 2021
S
I cannot deploy to Vercel with this command.
its throwing error:
I have also tried with
I have then tried with Lerna, then getting:
Any help?
"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 .." },
/bin/sh: sanity: command not found Command failed with exit code 127.
npx @sanity/cli build,
yarn build,
yarn && sanity buildand 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
S
Do you have
@sanity/clias a dependency in your
packages.json?
Jul 14, 2021, 1:07 PM
S
yes, I have it as dev dependencies for next.js root folder as well.
it sometime throws "some commands not available until sanity install"
it sometime throws "some commands not available until sanity install"
Jul 14, 2021, 1:09 PM
S
btw, the sanity project is in the /studio folder
Jul 14, 2021, 1:09 PM
S
Fwiw, I have
@sanity/clias a normal, non-dev dependency in my studio’s
packages.jsonand run
sanity buildon netlify with no issue
Jul 14, 2021, 1:12 PM
S
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
S
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
Also, if we are using
npxthen we don't need it to be in package.json right?
Jul 14, 2021, 1:14 PM
S
Locally, I guess you could use npx to run anything inside the
Vercel doesn’t know what’s inside your local node_modules folder, but will install everything in your
node_modulesfolder, 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
packages.jsonbefore building your site.
Jul 14, 2021, 1:25 PM
S
My
studio/packages.jsonlooks 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
S
I guess you need to make sure that
@sanity/cliis available in the
packages.jsonas a non-dev wherever your trying to use the command
sanity build
Jul 14, 2021, 1:29 PM
S
yes, still showing error. @core isalready there in the package.
I guess the issue is vercel is not taking the command of
I guess the issue is vercel is not taking the command of
cd studiosomehow. 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
D
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
S
What I would try:1. make sure
@sanity/cliin your
studio/packages.jsonas a normal dependency2. Make sure you have a “build command” in
studio/packages.json3. In your project root
packages.json, 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
S
Thanks man, I finally tried with
Yes, I also made sure to install
Thanks again.
"prebuild"and it worked.
Yes, I also made sure to install
yarnbefore 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
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.