Error with sanity typegen in monorepo

Open
#21 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start with the linked reproduction repository and run sanity typegen generate from the studio directory. Inspect ./src/queries/page.ts, compare its imported object and fragment strings, and trace how the command resolves @heaume/studio-globals/fragments; done means queries using imported fragments generate types without the reported binding error.

Written by the indexing model from the issue text.

Description

Describe the bug

I'm working with a turborepo monorepo containing a sanity studio app and a package build with tsdown containing standard objects and fragments for the sanity app.

I'm encountering errors when trying to generate the types for the sanity studio queries with imported fragments. The imported fragments are strings.
I've managed to import objects without issues and the schema extraction happens without any issue.

When running the sanity typegen generate command from the studio directory to generate the types from the queries and the existing schema, the queries using fragments from the monorepo package are breaking the type generation with following error:

✗ Could not find binding for import "fragments" in "@heaume/studio-globals/fragments" in "./src/queries/page.ts"

To Reproduce

Reproduction repo available here

Expected behavior

Typegen should work

Which versions of Sanity are you using?

@sanity/cli (global) 4.11.0 (latest: 4.12.0)
sanity 4.11.0 (latest: 4.12.0)

What operating system are you using?

linux mint

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

node v22.19.0
pnpm 10.19.0

Additional context

none

Dominant language
TypeScript
Stars
1
Forks
2
Avg merge
3d 11h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sanity-io/codegen

All issues in sanity-io/codegen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.