Next.js and Vercel - Error! No Output Directory named "dist" found

3 replies
Last updated: Aug 8, 2022
I'm trying to setup Sanity + NextJS with Vercel. I've read the tutorial and I am able to deploy, however, in the Vercel build step, I run into an error stating
Error! No Output Directory named "dist" found after the Build completed. You can configure the Output Directory in your Project Settings.
and the build fails.

In this repo however
https://github.com/sanity-io/sanity-nextjs-vercel-example there also is no /dist folder and /dist is also ignored via .gitignore. I am know wondering if I should in fact run
sanity build
to generate an output folder or if there is another way.
Thank you in advance!
AI Update

I can see what's happening here! This is a common confusion when setting up Sanity + Next.js on Vercel. The error you're seeing is related to Vercel's project configuration, not your actual project structure.

The issue is that Vercel is looking for a dist folder because it's been configured (or auto-detected) with the wrong build settings. When you deploy a Next.js application to Vercel, you should NOT be running sanity build as part of your deployment - that command is only for building a standalone Sanity Studio for self-hosting.

Solution: Update Your Vercel Project Settings

  1. Go to your Vercel project settings (Project Settings → General → Build & Development Settings)

  2. Set the correct Framework Preset: Select "Next.js" from the dropdown. This will automatically configure:

    • Build Command: next build (not sanity build)
    • Output Directory: .next (not dist)
    • Install Command: Automatically detected
  3. If you've manually set an Output Directory, remove it or change it to .next

Why This Happens

  • sanity build generates a dist folder containing a standalone Sanity Studio
  • next build generates a .next folder containing your Next.js application
  • The example repo you referenced has .gitignore entries for both because it may contain both a Next.js app AND an embedded Studio, but only the Next.js build is deployed to Vercel
  • When deploying a Next.js app with an embedded Studio (typically at /studio route), you only run next build - Next.js handles bundling the Studio as part of your application

Quick Check

If your project structure looks like this:

/app or /pages  (Next.js routes)
/sanity         (Sanity schema/config)
next.config.js
sanity.config.ts

Then you're building a Next.js app with embedded Studio, and you should use Next.js build settings on Vercel, not standalone Studio settings.

After updating these settings in Vercel, trigger a new deployment and it should build successfully!

In your Studio, can you double check that your
package.json
has
"build": "sanity build",
under the scripts section? Then, try running
npm run build
from to see if you get any errors.
There was my mistake! I had
"build": "sanity build public -y"
in my code, as stated in the Vercel documentation https://vercel.com/guides/deploying-sanity-studio-with-vercel . Thanks for clearing that up!
Awesome! Looks like we may have to make a change to that starter.

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?