xlanex6 / nuxt-meilisearch

🔎 Meilisearch module for Nuxt 3
https://nuxt-meilisearch.vercel.app
MIT License
117 stars 16 forks source link

$meilisearch is not defined #112

Closed alex3025 closed 5 months ago

alex3025 commented 6 months ago

When I run this code in my <script setup>:

const { availableIndexes, error } = await useAsyncData(async () => {
  const rawIndexes = await $meilisearch.getIndexes();  // This triggers the error
  return rawIndexes;
});

I get the following error:

ReferenceError: $meilisearch is not defined
    at http://localhost:3000/_nuxt/components/Search/IndexSelector.vue?t=1713863629542:30:26
    at Promise.then.result (http://localhost:3000/_nuxt/node_modules/.pnpm/nuxt@3.11.2_@parcel+watcher@2.4.1_@types+node@20.12.7_@unocss+reset@0.59.4_encoding@0.1.13_es_vs5t26qmp4vt6ccneqoti2yifm/node_modules/nuxt/dist/app/composables/asyncData.js?v=34b5c8a1:69:19)
    at new Promise (<anonymous>)
    at asyncData.refresh.asyncData.execute (http://localhost:3000/_nuxt/node_modules/.pnpm/nuxt@3.11.2_@parcel+watcher@2.4.1_@types+node@20.12.7_@unocss+reset@0.59.4_encoding@0.1.13_es_vs5t26qmp4vt6ccneqoti2yifm/node_modules/nuxt/dist/app/composables/asyncData.js?v=34b5c8a1:66:21)
    at initialFetch (http://localhost:3000/_nuxt/node_modules/.pnpm/nuxt@3.11.2_@parcel+watcher@2.4.1_@types+node@20.12.7_@unocss+reset@0.59.4_encoding@0.1.13_es_vs5t26qmp4vt6ccneqoti2yifm/node_modules/nuxt/dist/app/composables/asyncData.js?v=34b5c8a1:107:40)
    at useAsyncData (http://localhost:3000/_nuxt/node_modules/.pnpm/nuxt@3.11.2_@parcel+watcher@2.4.1_@types+node@20.12.7_@unocss+reset@0.59.4_encoding@0.1.13_es_vs5t26qmp4vt6ccneqoti2yifm/node_modules/nuxt/dist/app/composables/asyncData.js?v=34b5c8a1:141:7)
    at http://localhost:3000/_nuxt/components/Search/IndexSelector.vue?t=1713863629542:28:94
    at withAsyncContext (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/chunk-YWILYD4D.js?v=34b5c8a1:4817:19)
    at setup (http://localhost:3000/_nuxt/components/Search/IndexSelector.vue?t=1713863629542:28:64)
    at callWithErrorHandling (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/chunk-YWILYD4D.js?v=34b5c8a1:1659:19)
xlanex6 commented 5 months ago

Hi @alex3025

$meilisearch is only available in server side but you can const meilisearch = useMeiliSearchRef() into your script setup

https://nuxt-meilisearch.vercel.app/front-side/basic#usemeilisearchref

alex3025 commented 5 months ago

Oh ok, thanks.