Clean Next.js + Sanity
A Next.js app with Sanity Studio, an open-source React application that connects to your Sanity project’s hosted dataset. The Studio is configured locally and can then be deployed for content collaboration.
template-nextjs-clean.sanity.dev
If you already deployed with the Sanity + Vercel integration, skip to the Vercel section below and set up the local environment from there.
Run this in your terminal. It creates the app on your computer and walks you through a Sanity login if you need one.
npm create sanity@latest -- --template sanity-io/sanity-template-nextjs-clean
If the CLI fails, the error list is in the Sanity CLI help.
Go into the folder that was just created, then start both dev servers.
cd <your app name>
npm run dev
The Studio asks you to log in. Use the same Google, GitHub, or email account you used in the CLI.
The schema already includes Page, Post, Person, and Settings.
In the Studio, click “+ Create” and choose Post. Write it and publish. The post shows up on the Next.js app and on the Presentation tab in the Studio.
Optional. From the project root, this loads the included dataset into your Sanity project.
npm run import-sample-data
The Post type lives in studio/src/schemaTypes/post.ts. Add more document types the same way. The schema reference is in the Sanity schema docs.
The Next.js app is in /frontend and the Studio is in /studio. Both start out only on your machine.
From the Studio directory:
cd studio
npx sanity deploy
You pick a hostname, for example your-project.sanity.studio.
Host the frontend wherever you like. With Vercel and GitHub, the path is:
frontend).Open Sanity Manage, select the project, and click “Invite project members”. They can use the deployed Studio and edit with you.
Use this when the project was created through the Sanity + Vercel integration and you now want it running locally.
git clone <your-new-repo-url>
cd <your-repo-name>
npm install
cd frontend && npx vercel link && npx vercel env pull .env.local && cd ..
cp frontend/.env.local studio/.env.local
The frontend reads NEXT_PUBLIC_SANITY_PROJECT_ID, NEXT_PUBLIC_SANITY_DATASET, SANITY_API_READ_TOKEN, and related values. The Studio reads SANITY_STUDIO_PROJECT_ID and SANITY_STUDIO_DATASET. The same .env.local works for both, because each app only reads what it needs.
npm run dev. Next.js is on localhost:3000, Studio on localhost:3333. Sign in with the account you used during setup.npm run import-sample-data.cd studio && npx sanity deploy
Then set NEXT_PUBLIC_SANITY_STUDIO_URL in the Vercel project to that Studio URL, such as https://your-project.sanity.studio.