Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema extract fails if "flat" custom type #7801

Open
heggemsnes opened this issue Nov 12, 2024 · 1 comment
Open

Schema extract fails if "flat" custom type #7801

heggemsnes opened this issue Nov 12, 2024 · 1 comment
Labels
typegen Issues related to TypeScript types generation

Comments

@heggemsnes
Copy link

Describe the bug

Using a field like

defineType({
    name: 'externalLink',
    type: 'url',
    title: 'External Link',
  }),

Somewhere directly like:

defineType({
    name: 'pageWithExternalLink',
    type: 'document',
    title: 'Page With External Link',
    fields: [
      {
        name: 'title',
        type: 'string',
        title: 'Title',
      },
      {
        name: 'link',
        type: 'externalLink',
        title: 'External Link',
      },
    ],
  }),
  

Causes error on schema extract

> npm run extract-types


> [email protected] extract-types
> sanity schema extract --enforce-required-fields

❌️ Failed to extract schema, with enforced required fields

Error: Type "externalLink" not found
    at convertSchemaType (~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/@sanity/schema/lib/_internal.js:120:11)
    at createObject (~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/@sanity/schema/lib/_internal.js:125:63)
    at convertBaseType (~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/@sanity/schema/lib/_internal.js:64:83)
    at ~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/@sanity/schema/lib/_internal.js:58:18
    at Array.forEach (<anonymous>)
    at Object.extractSchema (~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/@sanity/schema/lib/_internal.js:54:33)
    at main (~/Documents/GitHub/sanity-template-nextjs-clean/studio/node_modules/sanity/lib/_internal/cli/threads/extractSchema.js:10:195)

To Reproduce

Steps to reproduce the behavior:

Check my forked repo from the clean next.js template: https://github.com/heggemsnes/sanity-template-nextjs-clean

I've changed the schemaTypes to the examples before.

Add a valid project ID and run npm run extract-types

Expected behavior

This is valid Sanity code (I think?) and works fine in the studio. Useful for reusable validations etc.

Which versions of Sanity are you using?

@sanity/cli (global) 3.62.0 (latest: 3.63.0)
@sanity/assist 3.0.8 (up to date)
@sanity/eslint-config-studio 4.0.0 (up to date)
@sanity/icons 3.4.0 (up to date)
@sanity/vision 3.61.0 (latest: 3.63.0)
sanity 3.62.2 (latest: 3.63.0)

What operating system are you using?

MacOS 14.3.1

Which versions of Node.js / npm are you running?

10.2.4
v20.11.0

@basharalidreesi
Copy link

basharalidreesi commented Nov 13, 2024

I've encountered this problem as well, but with a boolean type. To make TypeGen work, I had to comment out all instances of this custom type, run the TypeGen commands, then manually add the correct type definitions to the output file (which defeats the purpose).

@rexxars rexxars added the typegen Issues related to TypeScript types generation label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typegen Issues related to TypeScript types generation
Projects
None yet
Development

No branches or pull requests

3 participants