Type error with Sanity Studio

Hello,

I am helping a friend out with a Next.js project that utilizes Sanity. When attempting a preview build on Vercel, we keep getting the following error:

Type error: Page "src/app/studio/[[...tool]]/page.tsx" does not match the required types of a Next.js Page.
"viewport" is not a valid Page export field.

The contents of page.tsx is an exact copy of the example at The official Sanity toolkit for Next.js | Sanity.io plugin :

// ./src/app/studio/[[...tool]]/page.tsx

import {NextStudio} from 'next-sanity/studio'
import config from '../../../../sanity.config'

export const dynamic = 'force-static'

export {metadata, viewport} from 'next-sanity/studio'

export default function StudioPage() {
  return <NextStudio config={config} />
}

Locally, everything works fine. Has anyone else run into this issue before? I’m new to Vercel, Sanity and Next.js, but my jellies tell me it may be an environmental difference between Vercel and my local environment.

Any help would be greatly appreciated, thank you!

Hi,

The build step in App Router, does a strict check on what is exported from a page.tsx or page.jsx, or page.js, file.

In your case, you are exporting Container, but that is not allowed. You can have a:

You will likely need to use export {viewport} from 'next-sanity/studio/viewport' instead: next-sanity/packages/next-sanity/MIGRATE-v6-to-v7.md at main · sanity-io/next-sanity · GitHub. I will recommend reaching out to Sanity Studio support team once.

Hello,

Thank you for the quick response. I have tried using export {viewport} from 'next-sanity/studio/viewport', but that was deprecated in v9 and the recommendation is to use export {viewport} from 'next-sanity/studio', per next-sanity/packages/next-sanity/MIGRATE-v8-to-v9.md at main · sanity-io/next-sanity · GitHub

One thing I forgot to mention is that this only happens with preview builds, production builds are fine. Are these errors ignored for production builds? I’ve tried excluding src/app/studio in tsconfig.json with no luck either.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.