We are running a SPA compiled with vite and Vue3. As soon as we call the useStore() function inside a composable, we encounter a Type Error in the pinia code:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_s')
It happens in the pinia core code
We can use this store without issues anywhere else in our app (SPA). It seems that the composables are run too early and create this error because the pinia instance is not ready yet (similar issue here, albeit with SSG: https://github.com/antfu/vite-ssg/issues/103 )
- Create a dummy store import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Ref } from 'vue'
export const useTestStore = defineStore('customer-portal', () => {
console.log('Defining Teststore...')
const test: Ref<string> = ref('')
return {
test,
}
})
- Create a composable using this store:
import { ref } from 'vue'
import { useTestStore } from '@/vue/store/test'
const store = useTestStore()
- Use theat composable in a component (import store and call useTestStore())