Sanity v3 upgrade: Getting undefined error for products schema

7 replies
Last updated: Jan 4, 2023
Hello,So I made the mistake of trying to integrate shopify into my project and upgrading to v3 at the same time haha.

I am pretty sure I did the update right, I am getting a undefined error for my products though. Was wondering if you guys can check my schema file as see if its v3 compliant
AI Update

I totally understand the pain of doing two major changes at once - that definitely makes debugging trickier! Let me help you figure out what's going on with your product schema for v3.

First, the good news: when using Sanity Connect for Shopify, the product data structure is actually handled automatically by the integration. You don't need to manually define a store object field in your schema - that's created automatically when Shopify products sync to your Sanity dataset.

What Actually Happens with Sanity Connect:

When you install and configure Sanity Connect for Shopify, it automatically creates product documents in your Sanity dataset. The Shopify data (title, variants, prices, etc.) appears in a read-only store property on these documents, but this is handled by the integration itself, not something you define in your schema.

Your Product Schema Should Look Like This for v3:

import {defineType, defineField} from 'sanity'

export default defineType({
  name: 'product',
  title: 'Product',
  type: 'document',
  fields: [
    // Add your CUSTOM fields here - not the store object
    defineField({
      name: 'customDescription',
      title: 'Custom Description',
      type: 'text',
    }),
    defineField({
      name: 'seo',
      title: 'SEO',
      type: 'object',
      fields: [
        {name: 'title', type: 'string'},
        {name: 'description', type: 'text'}
      ]
    })
    // The 'store' object with Shopify data is added automatically
  ]
})

Key v3 Migration Points:

  1. Use defineType and defineField - This is the v3 standard for better TypeScript support
  2. Only define YOUR custom fields - Don't try to define the store object
  3. The store property appears automatically after sync completes

Common Causes of Your Undefined Error:

  1. Initial sync hasn't completed - After connecting Sanity Connect, it takes time for products to sync. Check your Sanity project's "Connect" section to see sync status.

  2. Accessing data incorrectly in queries - Shopify data lives under store, so your GROQ queries need:

    *[_type == "product"]{
      _id,
      "title": store.title,
      "slug": store.slug.current,
      "variants": store.variants,
      customDescription
    }
  3. Frontend code using wrong paths - Access product.store.title, not product.title

  4. Schema type name mismatch - Make sure your schema uses name: 'product' (or whatever document type Sanity Connect is syncing to)

Quick Debugging Steps:

  1. Check if products exist: Go to your Studio and look for product documents. Do they exist?

  2. Inspect a product document: Open one and click the three dots → "Inspect" to see the raw JSON. You should see a store object with Shopify data inside it.

  3. Verify the sync: In your Sanity project dashboard, check the Sanity Connect settings to confirm the sync is active and completed.

  4. Check your query/component: Where exactly are you getting the undefined error? Share the specific code line and error message if you can - that'll help pinpoint whether it's a schema issue, query issue, or frontend rendering issue.

The most likely culprit is either that the initial sync hasn't finished yet, or your code is trying to access Shopify fields directly instead of through the store object. Let me know what you find when you inspect a product document!

Show original thread
7 replies
/ Editor Imports
// Buttons
import buttonMain from "./components/editor/buttons/buttonMain";
import buttonAlt from "./components/editor/buttons/buttonAlt";
import buttonHero from "./components/editor/buttons/buttonHero";
import buttonSubmit from "./components/editor/buttons/buttonSubmit";
import buttonCard from "./components/editor/buttons/buttonCard";
import buttonIcon from "./components/editor/buttons/ButtonIcon";
// Cards
import bioCard from "./components/editor/cards/bioCard";
import picCard from "./components/editor/cards/picCard";
import picCardAlt from "./components/editor/cards/picCardAlt";
import iconCard from "./components/editor/cards/iconCard";
import contactCard from "./components/editor/cards/contactCard";
import infoCard from "./components/editor/cards/infoCard";
import serviceCard from "./components/editor/cards/serviceCard";
import bioCardAlt from "./components/editor/cards/bioCardAlt";
import backgroundCard from "./components/editor/cards/backgroundCard";
import priceCard from "./components/editor/cards/priceCard";
import linkCard from "./components/editor/cards/linkCard";
import faqCard from "./components/editor/cards/faqCard";
import flipCard from "./components/editor/cards/flipCard";
import blogCard from "./components/editor/cards/blogCard";
// CardArrays
import backgroundCards from "./components/editor/cards/cardsArrays/backgroundCards";
import bioCards from "./components/editor/cards/cardsArrays/bioCards";
import bioCardsAlt from "./components/editor/cards/cardsArrays/bioCardsAlt";
import contactCards from "./components/editor/cards/cardsArrays/contactCards";
import infoCards from "./components/editor/cards/cardsArrays/infoCards";
import serviceCards from "./components/editor/cards/cardsArrays/serviceCards";
import picCards from "./components/editor/cards/cardsArrays/picCards";
import picCardsAlt from "./components/editor/cards/cardsArrays/picCardsAlt";
import iconCards from "./components/editor/cards/cardsArrays/iconCards";
import priceCards from "./components/editor/cards/cardsArrays/priceCards";
import linkCards from "./components/editor/cards/cardsArrays/linkCards";
import faqCards from "./components/editor/cards/cardsArrays/faqCards";
import flipCards from "./components/editor/cards/cardsArrays/flipCards";
import blogCards from "./components/editor/cards/cardsArrays/blogCards";
// collages
import CollageArticle from "./components/editor/collages/CollageArticle";
// Images
import picture from "./components/editor/images/picture";
// Videos
import video from "./components/editor/video/video";
import videoArticle from "./components/editor/video/videoArticle";
// Statistics
import statistic from "./components/editor/statistics/statistic";
import statisticAlt from "./components/editor/statistics/statisticAlt";
// Statistics Array
import statistics from "./components/editor/statistics/statisticsArrays/statistics";
import statisticsAlt from "./components/editor/statistics/statisticsArrays/statisticsAlt";
// testimonials
import customerReview from "./components/editor/testimonials/customerReview";
import customerReviewAlt from "./components/editor/testimonials/customerReviewAlt";
import quote from "./components/editor/testimonials/quote";
// Testimonials Array
import customerReviews from "./components/editor/testimonials/testimonialsArray.js/customerReviews";
import customerReviewsAlt from "./components/editor/testimonials/testimonialsArray.js/customerReviewsAlt";
import quotes from "./components/editor/testimonials/testimonialsArray.js/quotes";
// Layout Imports
// Articles
import picArticle from "./components/layout/articles/picArticle";
import picArticleAlt from "./components/layout/articles/picArticleAlt";
// Banner
import banner from "./components/layout/banners/banner";
import infoBanner from "./components/layout/banners/infoBanner";
// Forms
import formMain from "./components/layout/forms/formMain";
import formAlt from "./components/layout/forms/formAlt";
import formPictureBackground from "./components/layout/forms/formPictureBackground";
// Heros
import heroMain from "./components/layout/heros/heroMain";
import heroAlt from "./components/layout/heros/heroAlt";
import heroText from "./components/layout/heros/heroText";
// Notifcations
import notifcationBar from "./components/layout/notifcations/notifcationBar";
import cookieConsent from "./components/layout/notifcations/cookieConsent";
// Premades
import picArticleFlip from "./components/layout/premade/picArticleFlip";
import pipArticle from "./components/layout/premade/pipArticle";
import sidebarArticle from "./components/layout/premade/sidebarArticle";
import articleImageGrid from "./components/layout/premade/articleImageGrid";
import statisticsArticleGrid from "./components/layout/premade/statisticsArticleGrid";
import normalPicArticle from "./components/layout/premade/normalPicArticle";
// Widgets
import miniForm from "./components/widgets/miniForm";
import sidebarContact from "./components/widgets/sidebarContact";

// Pricing
// -- Global Components--
// Headers
import headerMain from "./pages/headerFooter/headerMain";
// Footer
import footerMain from "./pages/headerFooter/footerMain";
// Theme
import brandColor from "./components/theme/brandColor";
import mainTheme from "./components/theme/mainTheme";
import fontOptions from "./components/theme/fontOptions";
import buttonTheme from "./components/theme/buttonTheme";

// Notifcations
// Ultilitys
import pic from "./components/ultilitys/pic";
import seo from "./components/ultilitys/seo";
import { socialArray, socialHandle } from "./components/ultilitys/socialHandle";
import editor from "./components/ultilitys/editor";
import simpleEditor from "./components/ultilitys/simpleEditor";
import layout from "./components/ultilitys/layout";
import basicEditor from "./components/ultilitys/basicEditor";
import linkOptions from "./components/ultilitys/linkOptions";
import youtube from "./components/ultilitys/youtube";
import map from "./components/ultilitys/map";
import {
  editorBulletList,
  bulletListHelper,
} from "./components/ultilitys/editorBulletList";
import {
  contactInfo,
  contactInfoArray,
} from "./components/ultilitys/contactInfo";
// Pages
import siteInfo from "./pages/siteSettings/siteInfo";
import siteTheme from "./pages/siteSettings/siteTheme";
import widgets from "./pages/siteSettings/widgets";
import index from "./pages/index";
import about from "./pages/about";
import contact from "./pages/contact";
import serviceMain from "./pages/serviceMain";
import usecases from "./pages/usecases";
import blog from "./pages/blog";
// Posts
import usecasePosts from "./pages/templates/usecasePosts";
import servicePosts from "./pages/templates/servicePosts";
import blogPosts from "./pages/templates/blogPosts";
import bioPosts from "./pages/templates/bioPosts";
import customPage from "./pages/templates/customPage";

// Theme Pages
// Buttons
import altButtonTheme from "./pages/siteSettings/componentThemes/buttons/altButtonTheme";
import cardButtonTheme from "./pages/siteSettings/componentThemes/buttons/cardButtonTheme";
import heroButtonTheme from "./pages/siteSettings/componentThemes/buttons/heroButtonTheme";
import mainButtonTheme from "./pages/siteSettings/componentThemes/buttons/mainButtonTheme";
import submitButtonTheme from "./pages/siteSettings/componentThemes/buttons/submitButtonTheme";
// Cards
import backgroundCardTheme from "./pages/siteSettings/componentThemes/cards/backgroundCardTheme";
import bioCardAltTheme from "./pages/siteSettings/componentThemes/cards/bioCardAltTheme";
import bioCardTheme from "./pages/siteSettings/componentThemes/cards/bioCardTheme";
import contactCardTheme from "./pages/siteSettings/componentThemes/cards/contactCardTheme";
import iconCardTheme from "./pages/siteSettings/componentThemes/cards/iconCardTheme";
import infoCardTheme from "./pages/siteSettings/componentThemes/cards/infoCardTheme";
import picCardAltTheme from "./pages/siteSettings/componentThemes/cards/picCardAltTheme";
import picCardTheme from "./pages/siteSettings/componentThemes/cards/picCardTheme";
import serviceCardTheme from "./pages/siteSettings/componentThemes/cards/serviceCardTheme";
import priceCardTheme from "./pages/siteSettings/componentThemes/cards/priceCardTheme";
import linkCardTheme from "./pages/siteSettings/componentThemes/cards/linkCardTheme";
import faqCardTheme from "./pages/siteSettings/componentThemes/cards/faqCardTheme";
import flipCardTheme from "./pages/siteSettings/componentThemes/cards/flipCardTheme";
import blogCardTheme from "./pages/siteSettings/componentThemes/cards/blogCardTheme";
// Pics

// Collages
import picCollageTheme from "./pages/siteSettings/componentThemes/collages/picCollageTheme";
// Statistics
import statisticsAltTheme from "./pages/siteSettings/componentThemes/statistics/statisticsAltTheme";
import statisticsMainTheme from "./pages/siteSettings/componentThemes/statistics/statisticsMainTheme";
// Testimonials
import customerReviewAltTheme from "./pages/siteSettings/componentThemes/testimonials/customerReviewAltTheme";
import customerReviewTheme from "./pages/siteSettings/componentThemes/testimonials/customerReviewTheme";
import quotesTheme from "./pages/siteSettings/componentThemes/testimonials/quotesTheme";
// Editor Themes
// Videos
import videoArticleTheme from "./pages/siteSettings/componentThemes/videos/videoArticleTheme";
// Ecom Section ------------
// Components
import collectionRule from "./components/ecom/collectionRule";
import shopifyCollection from "./components/ecom/shopifyCollection";
import shopifyProudct from "./components/ecom/shopifyCollection";
import shopifyProudctVariant from "./components/ecom/shopifyProductVariant";

// Inputs
// import CollectionHidden from "./components/ecom/inputs/CollectionHidden";
// import PlaceholderString from "./components/ecom/inputs/PlaceholderString";
// import ProductHidden from "./components/ecom/inputs/ProductHidden";
// import ProductVariantHidden from "./components/ecom/inputs/ProductVariantHidden";
// import ProxyString from "./components/ecom/inputs/ProxyString";

// pages
import collection from "./pages/ecom/collection";
import proudct from "./pages/ecom/product";
import productVariant from "./pages/ecom/productVariant";
export default [
  /* Your types here! */
  buttonMain,
  buttonAlt,
  buttonHero,
  buttonIcon,
  buttonSubmit,
  video,
  videoArticle,
  buttonCard,
  backgroundCard,
  bioCard,
  bioCardAlt,
  iconCard,
  picCard,
  picCardAlt,
  contactCard,
  infoCard,
  serviceCard,
  linkOptions,
  CollageArticle,
  picArticle,
  picArticleAlt,
  faqCard,
  picture,
  flipCard,
  flipCards,
  statistic,
  statisticAlt,
  statistics,
  statisticsAlt,
  customerReview,
  customerReviewAlt,
  quote,
  youtube,
  normalPicArticle,
  bulletListHelper,
  editorBulletList,
  contactInfo,
  contactInfoArray,
  statisticsArticleGrid,
  customerReviews,
  priceCard,
  customerReviewsAlt,
  cookieConsent,
  quotes,
  banner,
  infoBanner,
  formMain,
  formAlt,
  miniForm,
  formPictureBackground,
  footerMain,
  headerMain,
  sidebarArticle,
  sidebarContact,
  articleImageGrid,
  heroMain,
  heroAlt,
  heroText,
  notifcationBar,
  picArticleFlip,
  pic,
  seo,
  socialHandle,
  socialArray,
  siteInfo,
  siteTheme,
  priceCardTheme,
  widgets,
  editor,
  map,
  layout,
  mainTheme,
  index,
  basicEditor,
  simpleEditor,
  serviceMain,
  about,
  contact,
  blog,
  usecases,
  usecasePosts,
  servicePosts,
  customPage,
  blogPosts,
  bioPosts,
  backgroundCards,
  bioCards,
  blogCard,
  blogCards,
  bioCardsAlt,
  contactCards,
  iconCards,
  infoCards,
  priceCards,
  linkCard,
  picCards,
  picCardsAlt,
  serviceCards,
  faqCards,
  linkCards,
  pipArticle,
  altButtonTheme,
  cardButtonTheme,
  heroButtonTheme,
  mainButtonTheme,
  submitButtonTheme,
  backgroundCardTheme,
  bioCardAltTheme,
  bioCardTheme,
  blogCardTheme,
  contactCardTheme,
  iconCardTheme,
  infoCardTheme,
  picCardAltTheme,
  picCardTheme,
  flipCardTheme,
  serviceCardTheme,
  linkCardTheme,
  picCollageTheme,
  statisticsMainTheme,
  statisticsAltTheme,
  customerReviewAltTheme,
  customerReviewTheme,
  quotesTheme,
  videoArticleTheme,
  faqCardTheme,
  brandColor,
  fontOptions,
  buttonTheme,
  collection,
  collectionRule,
  shopifyCollection,
  product,
  shopifyProudct,
  productVariant,
  shopifyProudctVariant,
];
Looks like you've got a typo in your import!
import proudct from "./pages/ecom/product";
thank you!!I have this funny error now. I copied the product page from the shopify starter. Its structured alot differently than normal. Do you think that could be the issue?
Hmmm, can you share your
./pages/ecom/product.js
file?
Can i pm you my repo
Sounds good!

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?