Testing Next.js build locally like Gatsby build && serve

3 repliesLast updated: Nov 29, 2025

Coming to Next from Gatsby. Is there a equivalent for testing a build locally to detect for differences?
For Gatsby I’d run
gatsby build && gatsby serve
AI Update

The Next.js equivalent to gatsby build && gatsby serve is:

npm run build && npm run start

or if you're using pnpm/yarn:

pnpm build && pnpm start
# or
yarn build && yarn start

This works the same way as your Gatsby workflow:

This lets you test the production build locally to catch any differences between development and production mode before deploying. Common differences you might catch include:

If you're also running Sanity Studio alongside your Next.js app (like in a monorepo), you can test a production build of the Studio locally with npm run build in the Studio directory, as mentioned in the Sanity Studio development docs.

The production build is important to test because Next.js behaves quite differently in development mode (with features like Fast Refresh, more verbose error messages, and unoptimized bundles) compared to the optimized production build that gets deployed.

Show original thread
3 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