DEV Community

Discussion on: Introduction to Nuxt 3 modules

Collapse
 
jannikbuscha profile image
Jannik Buscha

Hey, very nice article, I am currently trying to use strapi in nuxt3 however $strapi is no longer injected globally for me. I only get Unresolved variable $strapi / Cannot read properties of undefined (reading '$strapi') error messages. Do you have any idea what the problem could be?

Collapse
 
jacobandrewsky profile image
Jakub Andrzejewski

Hi Jannik, I am glad you liked the article!
I think that the current approach for accessing integration variables (like we used this.$strapi in Nuxt 2) is now transitioned into using nuxt app composable or runtime config composable (useNuxtApp/useRuntimeConfig). Can you try to use any of these composables in your setup function? Something like this

<script setup>
const { $strapi } = useNuxtApp();
const { $strapi } = useRuntimeConfig();
</script>
Enter fullscreen mode Exit fullscreen mode

useRuntimeConfig should do the thing due to this line -> github.com/nuxt-community/strapi-m... but useNuxtApp can be useful for some older Nuxt modules that used to override the context. Let me know if that fixed the issue for you.

Collapse
 
jannikbuscha profile image
Jannik Buscha

Have yet found something hidden in the docu regarding nuxt3 and strapi 4. $strapi was replaced by the auto imported useStrapi4. But thanks for your answer that I can use very well for older nuxt libraries :)