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] Errors using client in an esm module #286

Closed madeleineostoja closed 1 year ago

madeleineostoja commented 1 year ago

I'm trying to use the generated typed client from @sanity-codegen/client in an ESM package (ie: type: "module" in package.json) and I'm getting not found errors trying to import anything, along with warnings from node about loading files as ES modules.

My typed client (same as in docs)

import { wrapClient } from '@sanity-codegen/client';

const sanityClient = createClient(...),
  typedClient = wrapClient(sanityClient),
  sanity = typedClient<Sanity.Default.Client.Config>();

export { sanity }

Import errors

Cannot read properties of undefined (reading 'wrapClient')
Cannot read properties of undefined (reading 'groq')

Node warning:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.