Error encountered while creating new content on the CMS in Sanity v3.
4 replies
Last updated: Oct 6, 2023
F
Hello,I need help with a an existing project that I have taken over. We have suddenly encountered this error, when ever our content creaters are trying to create new content on the CMS we are getting the following error:.
`An error was thrown while trying to get your preview url: An error occurred while resolving
We have updated to sanity v3, and I made the following changes to resolveProductionUrl.js changed document.slug.current to document._id and also changed the apiVersion: ‘2023-06-27’,
This has resolved the error in my local sanity environment but its still there in the CMS. Please help.
and sanity.config.js looks like this
`An error was thrown while trying to get your preview url: An error occurred while resolving
resolveProductionUrlfrom Production: Cannot read properties of undefined (reading 'current')`
We have updated to sanity v3, and I made the following changes to resolveProductionUrl.js changed document.slug.current to document._id and also changed the apiVersion: ‘2023-06-27’,
This has resolved the error in my local sanity environment but its still there in the CMS. Please help.
export default function resolveProductionUrl(document) { console.log(document._type) const siteUrl = '<https://www>.********' if (document._type == 'page' || document._type == 'landingpage') { const url = `${siteUrl}/api/preview?slug=/${document._id}` console.log('Preview URL:', url) return url } if (document._type == 'work') { const url = `${siteUrl}/api/preview?slug=/work/${document._id}` console.log('Preview URL:', url) return url } if (document._type == 'stories') { const url = `${siteUrl}/api/preview?slug=/stories/${document._id}` console.log('Preview URL:', url) return url } console.error('Unrecognized document type:', document._type) }
import { defineConfig, definePlugin } from "sanity"; import { deskTool } from "sanity/desk"; import schemas from "./schemas/schema"; import resolveProductionUrl from './resolveProductionUrl' const sharedConfig = definePlugin({ plugins: [deskTool()], schema: { types: schemas, } }); export default defineConfig([ { name: "Production", title: "Production", projectId: "******", dataset: "production", basePath: "/prod", plugins: [sharedConfig()], document: { productionUrl: async (prev, context) => { return resolveProductionUrl(context.document); }, }, }, { name: "staging", title: "Staging", projectId: "*******", dataset: "development", basePath: "/staging", plugins: [sharedConfig()], }, ]);
Oct 5, 2023, 7:10 AM
F
Yes, turns out we forgot to run sanity deploy.
Oct 6, 2023, 6:29 AM
F
works fine now.
Oct 6, 2023, 6:29 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.