johannschopplich / kirby-nuxt-starterkit

💚 Kirby's sample site – ported to Nuxt and Kirby Query Language
https://kirby-nuxt-starter.pages.dev
MIT License
51 stars 2 forks source link

Module `"#nuxt-kql"` has no exported member `KirbySite` #5

Closed Jorckx closed 1 month ago

Jorckx commented 1 month ago

Since recently I get this message within my site.ts composable. Also now when using your repository as a template. This also affects other composables which consume the useSite() composable. On my Imac however I do'nt have this problem. Can you help me figure out what's going wrong? I'm not aware of any changes that have led to this.

johannschopplich commented 1 month ago

The error indicated that the type KirbySite is missing. You've probably deleted the kirbySite prefetch query from your Nuxt config: https://github.com/johannschopplich/kirby-nuxt-starterkit/blob/7464bc1e9d30038f4cf5ea37aa8763b7fe1b87df/nuxt.config.ts#L16. It is intended to fetch the site data at build-time to get a type-complete result when using the useSite composable.

I recommend you add the kirbySite prefetch query back.

Alternatively, you can make the type more generic:

export function useSite() {
  return useState<Record<string, any>>('app.site', () => ({}))
}
Jorckx commented 1 month ago

It's happening at import type { KirbySite } from '#nuxt-kql' in site.ts composable. Scherm­afbeelding 2024-08-20 om 07 39 28

It's trying to import the type KirbySite, not the prefetched siteQuery, or am I wrong? Somehow It can't find the type… In my nuxt.cofig I didn't change anything, the kirbySite is prefetched as it was. In addition this also affects all the useSite() composables since they 'can not be found'. It's very strange since I've build many sites using this your repository a template.

johannschopplich commented 1 month ago

Yes, the KirbySite type is inferred from the kirbySite result object. You can check out .nuxt/module/nuxt-kql.ts to see all your prefetched query results.

Have you run pnpm dev, respectively npm run dev depending on your package manager, once? Seems like the query hasn't been fetched. You need to run the dev server (or pnpm prepare) once to generate this file. If you've freshly cloned the repo, the prefetchable query hasn't been fetched, so the type is missing.