Error displaying projects in page.tsx while following Kapehe's Sanity tutorial

8 replies
Last updated: Nov 29, 2025
Hello! I'm excited for this project https://www.youtube.com/watch?v=OcTPaUfay5I&t=1325s by Kapehe to work. I've gone back and rebuilt the whole project on a brand new Mac after first trying on a Linux machine and I still get the same error when we begin getting the page.tsx ready to display the projects. The admin section works just fine... Please help cuz I'm excited how these technologies tie together. The tutorial is amazing by the way and can't wait to get past this bump. Thank you!
AI Update

I'd love to help you get past this error! I can see you're following Kapehe's Next.js 13 & Sanity Studio v3 tutorial, which is a great resource for building a personal portfolio site.

Since you mentioned the admin section (Sanity Studio) works fine but you're having issues when setting up page.tsx to display projects, here are the most common issues and solutions:

Common Issues & Solutions

1. Environment Variables Make sure your .env.local file in your Next.js project root contains:

NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id
NEXT_PUBLIC_SANITY_DATASET=production
NEXT_PUBLIC_SANITY_API_VERSION=2024-01-01

2. GROQ Query Syntax If you're using TypeScript, queries need to be wrapped with defineQuery:

import { defineQuery } from 'next-sanity'

const projectsQuery = defineQuery(`*[_type == "project"]`)

3. Sanity Client Configuration Verify your Sanity client is properly configured with your project ID and dataset. Check your sanity.config.ts or client initialization file.

4. CORS Settings If you're getting network errors, add your localhost to CORS origins:

  • Go to sanity.io/manage
  • Select your project → API → CORS Origins
  • Add http://localhost:3000 (or whatever port you're using)

5. Next.js Version Differences The tutorial uses Next.js 13, but if you're on Next.js 15, be aware that route params are now promises and need to be awaited:

// Next.js 15
export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params
}

6. API Perspective Change If you're using the latest Sanity APIs, note that the default perspective changed to published in API version 2025-02-19. You might need to explicitly set the perspective to raw if you want to see drafts.

What I Need From You

To give you more specific help, could you share:

  1. The exact error message you're seeing (console or browser error)
  2. Your page.tsx code where you're fetching projects
  3. Which Next.js version you're using (package.json)
  4. Whether you can see your project documents in Vision (Sanity Studio → Vision tab)

The fact that this happens on both Mac and Linux suggests it's a configuration or code issue rather than an environment problem. Drop the error details here and I'll help you troubleshoot further!

Show original thread
8 replies

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?