ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

[v1][client] Typed client fails to resolve imports with typescript aliases used in queries #289

Open madeleineostoja opened 1 year ago

madeleineostoja commented 1 year ago

I have snippets that I reuse in my queries, which I import from a file. That file import is aliased, configured both in Typescript and Vite (used in a Sveltekit app), but the client tries to resolve these imports and fails.

Eg:

import { groq, sanity } from '$src/lib/sanity';
import { asset } from '$src/lib/fragments';

sanity('Foo', groq`
  * {
   image {
     ${asset}
   }
`)

Resulting error:

 [default] Generating types for workspace `default`    Error: Cannot find module '$src/lib/fragments'

Rewriting the asset snippet import to not use an alias fixes the error, but is an annoying workaround


EDIT: This is kinda redundant if this issue can't be resolved: #290