Currently I am doing something like this to import stores in components
import { useSomeStore } from "~/store/someStore";
const store = useSomeStore();
What I would like to achieve is skip the import and just use the store
What I have done is add
// nuxt.config.ts
modules: [
[
"@pinia/nuxt",
{
autoImports: ["defineStore", "acceptHMRUpdate"],
},
],
],
imports: {
dirs: ["stores"],
},
in my nuxt config but I'm still getting useSomeStore is undefined, what am I doing wrong in this case?
The store:
// store/someStore.ts
export const useSomeStore = defineStore("some-store", {
state: () => ({ hello: "there" }),
});
useSomeStore
undefined
is not the same as not havingdefineStore
imported. You would have aTypeError defineStore is not a function
at runtime if it was the case. Also, does the Typescript compiler complains aboutdefineStore
or not? – Preeminence