โœจDiscover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8thโ€”register now

Issues with deploying GraphQL after upgrading from V2 to V3 Sanity

6 replies
Last updated: Feb 9, 2023
Hello ๐Ÿ‘‹
Since the upgrade from V2 to V3 sanity, I'm having issues running
sanity graphql deploy
,

production: Could not resolve source `production`:
        - An error occurred while resolving `tools` from production: Cannot read properties of undefined (reading 'PRODUCTION'
I have tried searching through different similar threads, although couldn't figure out where the issue is.
Feb 4, 2023, 12:39 AM
sanity.cli.js

// sanity.cli.js
import {defineCliConfig} from 'sanity/cli'
import * as dotenv from 'dotenv'

export default defineCliConfig({
  api: {
    projectId: 'XXXX', // replace value with your own
    dataset: 'dev' // replace value with your own
  },
  graphql: [
    {
      id: "production",
      workspace: "production",
    },
    {
      id: "dev",
      workspace: "dev",
    },
  ],
})

Feb 4, 2023, 12:40 AM
sanity.config.js

// sanity.config.js
import { defineConfig } from "sanity";
import { deskTool } from 'sanity/desk'
import schemas from './schemas/schema'
import { table } from '@sanity/table';
import { colorInput } from "@sanity/color-input";
import deskStructure from './sidebar'
import { visionTool } from '@sanity/vision'
import * as dotenv from 'dotenv'

export default defineConfig([{
  title: "XXX Dev",
  projectId: "XXX ",
  dataset: "dev",
  name: "dev",
  basePath: '/dev',
  plugins: [deskTool({structure: deskStructure}),
    visionTool(),
    table(),
    colorInput()],
    tools: (prev) => {
      // ๐Ÿ‘‡ Uses environment variables set by Vite in development mode
      if (import.meta.env.DEV) {
        return prev
      }
      return prev.filter((tool) => tool.name !== 'vision')
},
  schema: {
    types: schemas,
  },
  document: {
    newDocumentOptions: (prev, { creationContext }) => {
      if (creationContext.type === 'global') {
        return prev.filter((templateItem) => templateItem.templateId != 'settings')
      }
      return prev
    },
    actions: (prev, { schemaType }) => {
      if (schemaType === 'settings') {
        return prev.filter(({ action }) => !['unpublish', 'delete','duplicate'].includes(action))
      }
      return prev
    },
  },
},
{
  title: "XXX Prod",
  projectId: "XXX",
  dataset: "production",
  name: "production",
  basePath: '/production',
  plugins: [deskTool({structure: deskStructure}),
    visionTool(),
    table(),
    colorInput()],
    tools: (prev) => {
      // ๐Ÿ‘‡ Uses environment variables set by Vite in development mode
      if (import.meta.env.PRODUCTION) {
        return prev
      }
      return prev.filter((tool) => tool.name !== 'vision')
},
  schema: {
    types: schemas,
  },
  document: {
    newDocumentOptions: (prev, { creationContext }) => {
      if (creationContext.type === 'global') {
        return prev.filter((templateItem) => templateItem.templateId != 'settings')
      }
      return prev
    },
    actions: (prev, { schemaType }) => {
      if (schemaType === 'settings') {
        return prev.filter(({ action }) => !['unpublish', 'delete','duplicate'].includes(action))
      }
      return prev
    },
  },
}]);

Feb 4, 2023, 12:40 AM
Would anyone have any thoughts on this? ๐Ÿ™ˆ ๐Ÿ™
Feb 8, 2023, 10:28 PM
I donโ€™t see anything obviously wrong, but i also donโ€™t use the rplugin. I know they moved from
process.env
๐Ÿ‘‰
import.meta.env
which you seem to be using. Maybe pop open sanity graphql and peek under the hood? Are you on the latest version?
Feb 8, 2023, 11:04 PM
Are you using a tag when deploying? Seems similar to what was happening here .
Feb 8, 2023, 11:10 PM
Thanks both. It was the
process.env
and
import.meta.env
This post helped:

https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1671819526675779
Changing
import.meta.env.PRODUCTION
to
import.meta.PRODUCTION
allowed me to deploy graphql. I shall have a play to get the pipelines up and running ๐Ÿ™‚
Feb 9, 2023, 12:09 AM

Sanityโ€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?