Troubleshooting embedding Sanity Studio into a Next.js app with live preview
sanity.config.tsdefined. Have you created that in the root directory of your app?
{
"name": "kc-portfolio",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@heroicons/react": "^2.0.13",
"@next/font": "13.1.4",
"@portabletext/react": "^2.0.1",
"@sanity/image-url": "^1.0.2",
"@types/node": "18.11.18",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"eslint": "8.32.0",
"eslint-config-next": "13.1.4",
"framer-motion": "^8.5.0",
"next": "13.1.4",
"next-sanity": "^4.1.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.42.1",
"react-simple-typewriter": "^5.0.1",
"react-social-icons": "^5.15.0",
"typescript": "4.9.4",
"@sanity/vision": "^3.0.0",
"sanity": "^3.0.0",
"styled-components": "^5.2.0",
"sanity-plugin-media": "^2.0.4"
},
"devDependencies": {
"autoprefixer": "^10.4.13",
"postcss": "^8.4.21",
"tailwind-scrollbar": "^2.1.0",
"tailwindcss": "^3.2.4",
"@sanity/eslint-config-studio": "^2.0.1"
}
}import { createClient } from "next-sanity";
import createImageUrlBuilder from "@sanity/image-url";
export const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
apiVersion: "2021-10-21",
useCdn: process.env.NODE_ENV === "production",
};
// Set up client to get data in getProps page function.
export const sanityClient = createClient(config);
export const urlFor = (source: any) =>
createImageUrlBuilder(config).image(source);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.