Search code examples
vue.jsvuexvuejs3

Vuejs 3 Pinia not working, Cannot read properties of undefined (reading 'startsWith')


I try to use Pinia but it never works. Doesn't matter if I install it with Vite at the start of the project or if I add it later. It always write the same error. This is an example from my last project.

enter image description here

This is my main.js

import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import draggable from "vuedraggable";

const app = createApp(App);

app.use(createPinia());
app.component('draggable', draggable);
app.mount("#app");

This is start of my App.vue

<script setup>
import { ref } from "vue";
import draggable from "vuedraggable";
import {useCounterStore} from "./stores/counter";
const storeCounter = useCounterStore();

The error appears when I enter

const storeCounter = useCounterStore();

Solution

  • I did tests in Firefox instead of Chrome and the explanation was much better. It told me I was missing "id: counter" in my counter.js in "export const counter".

    enter image description here